Search in sources :

Example 1 with Carrier

use of android.hardware.radio.V1_0.Carrier in project android_frameworks_opt_telephony by LineageOS.

the class RIL method setAllowedCarriers.

@Override
public void setAllowedCarriers(List<CarrierIdentifier> carriers, Message result) {
    checkNotNull(carriers, "Allowed carriers list cannot be null.");
    IRadio radioProxy = getRadioProxy(result);
    if (radioProxy != null) {
        RILRequest rr = obtainRequest(RIL_REQUEST_SET_ALLOWED_CARRIERS, result, mRILDefaultWorkSource);
        if (RILJ_LOGD) {
            String logStr = "";
            for (int i = 0; i < carriers.size(); i++) {
                logStr = logStr + carriers.get(i) + " ";
            }
            riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) + " carriers = " + logStr);
        }
        boolean allAllowed;
        if (carriers.size() == 0) {
            allAllowed = true;
        } else {
            allAllowed = false;
        }
        CarrierRestrictions carrierList = new CarrierRestrictions();
        for (CarrierIdentifier ci : carriers) {
            /* allowed carriers */
            Carrier c = new Carrier();
            c.mcc = convertNullToEmptyString(ci.getMcc());
            c.mnc = convertNullToEmptyString(ci.getMnc());
            int matchType = CarrierIdentifier.MatchType.ALL;
            String matchData = null;
            if (!TextUtils.isEmpty(ci.getSpn())) {
                matchType = CarrierIdentifier.MatchType.SPN;
                matchData = ci.getSpn();
            } else if (!TextUtils.isEmpty(ci.getImsi())) {
                matchType = CarrierIdentifier.MatchType.IMSI_PREFIX;
                matchData = ci.getImsi();
            } else if (!TextUtils.isEmpty(ci.getGid1())) {
                matchType = CarrierIdentifier.MatchType.GID1;
                matchData = ci.getGid1();
            } else if (!TextUtils.isEmpty(ci.getGid2())) {
                matchType = CarrierIdentifier.MatchType.GID2;
                matchData = ci.getGid2();
            }
            c.matchType = matchType;
            c.matchData = convertNullToEmptyString(matchData);
            carrierList.allowedCarriers.add(c);
        }
        try {
            radioProxy.setAllowedCarriers(rr.mSerial, allAllowed, carrierList);
        } catch (RemoteException | RuntimeException e) {
            handleRadioProxyExceptionForRR(rr, "setAllowedCarriers", e);
        }
    }
}
Also used : IRadio(android.hardware.radio.V1_0.IRadio) CarrierRestrictions(android.hardware.radio.V1_0.CarrierRestrictions) CarrierIdentifier(android.service.carrier.CarrierIdentifier) Carrier(android.hardware.radio.V1_0.Carrier) RemoteException(android.os.RemoteException)

Example 2 with Carrier

use of android.hardware.radio.V1_0.Carrier in project android_frameworks_opt_telephony by LineageOS.

the class RIL method createCarrierRestrictionList.

/**
 * Convert a list of CarrierIdentifier into a list of Carrier defined in 1.0/types.hal.
 * @param carriers List of CarrierIdentifier
 * @return List of converted objects
 */
@VisibleForTesting
public static ArrayList<Carrier> createCarrierRestrictionList(List<CarrierIdentifier> carriers) {
    ArrayList<Carrier> result = new ArrayList<>();
    for (CarrierIdentifier ci : carriers) {
        Carrier c = new Carrier();
        c.mcc = convertNullToEmptyString(ci.getMcc());
        c.mnc = convertNullToEmptyString(ci.getMnc());
        int matchType = CarrierIdentifier.MatchType.ALL;
        String matchData = null;
        if (!TextUtils.isEmpty(ci.getSpn())) {
            matchType = CarrierIdentifier.MatchType.SPN;
            matchData = ci.getSpn();
        } else if (!TextUtils.isEmpty(ci.getImsi())) {
            matchType = CarrierIdentifier.MatchType.IMSI_PREFIX;
            matchData = ci.getImsi();
        } else if (!TextUtils.isEmpty(ci.getGid1())) {
            matchType = CarrierIdentifier.MatchType.GID1;
            matchData = ci.getGid1();
        } else if (!TextUtils.isEmpty(ci.getGid2())) {
            matchType = CarrierIdentifier.MatchType.GID2;
            matchData = ci.getGid2();
        }
        c.matchType = matchType;
        c.matchData = convertNullToEmptyString(matchData);
        result.add(c);
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) CarrierIdentifier(android.service.carrier.CarrierIdentifier) Carrier(android.hardware.radio.V1_0.Carrier) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Example 3 with Carrier

use of android.hardware.radio.V1_0.Carrier in project android_frameworks_opt_telephony by LineageOS.

the class RILTest method testCreateCarrierRestrictionList.

@Test
public void testCreateCarrierRestrictionList() {
    ArrayList<CarrierIdentifier> carriers = new ArrayList<>();
    carriers.add(new CarrierIdentifier("110", "120", null, null, null, null));
    carriers.add(new CarrierIdentifier("210", "220", "SPN", null, null, null));
    carriers.add(new CarrierIdentifier("310", "320", null, "012345", null, null));
    carriers.add(new CarrierIdentifier("410", "420", null, null, "GID1", null));
    carriers.add(new CarrierIdentifier("510", "520", null, null, null, "GID2"));
    Carrier c1 = new Carrier();
    c1.mcc = "110";
    c1.mnc = "120";
    c1.matchType = CarrierIdentifier.MatchType.ALL;
    Carrier c2 = new Carrier();
    c2.mcc = "210";
    c2.mnc = "220";
    c2.matchType = CarrierIdentifier.MatchType.SPN;
    c2.matchData = "SPN";
    Carrier c3 = new Carrier();
    c3.mcc = "310";
    c3.mnc = "320";
    c3.matchType = CarrierIdentifier.MatchType.IMSI_PREFIX;
    c3.matchData = "012345";
    Carrier c4 = new Carrier();
    c4.mcc = "410";
    c4.mnc = "420";
    c4.matchType = CarrierIdentifier.MatchType.GID1;
    c4.matchData = "GID1";
    Carrier c5 = new Carrier();
    c5.mcc = "510";
    c5.mnc = "520";
    c5.matchType = CarrierIdentifier.MatchType.GID2;
    c5.matchData = "GID2";
    ArrayList<Carrier> expected = new ArrayList<>();
    expected.add(c1);
    expected.add(c2);
    expected.add(c3);
    expected.add(c4);
    expected.add(c5);
    ArrayList<Carrier> result = RIL.createCarrierRestrictionList(carriers);
    assertTrue(result.equals(expected));
}
Also used : CarrierIdentifier(android.service.carrier.CarrierIdentifier) ArrayList(java.util.ArrayList) Carrier(android.hardware.radio.V1_0.Carrier) FlakyTest(androidx.test.filters.FlakyTest) Test(org.junit.Test)

Example 4 with Carrier

use of android.hardware.radio.V1_0.Carrier in project android_frameworks_opt_telephony by LineageOS.

the class RIL method setAllowedCarriers.

@Override
public void setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules, Message result, WorkSource workSource) {
    riljLog("RIL.java - setAllowedCarriers");
    checkNotNull(carrierRestrictionRules, "Carrier restriction cannot be null.");
    workSource = getDeafultWorkSourceIfInvalid(workSource);
    IRadio radioProxy = getRadioProxy(result);
    if (radioProxy == null)
        return;
    RILRequest rr = obtainRequest(RIL_REQUEST_SET_ALLOWED_CARRIERS, result, workSource);
    if (RILJ_LOGD) {
        riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) + " params: " + carrierRestrictionRules);
    }
    // Extract multisim policy
    int policy = SimLockMultiSimPolicy.NO_MULTISIM_POLICY;
    switch(carrierRestrictionRules.getMultiSimPolicy()) {
        case CarrierRestrictionRules.MULTISIM_POLICY_ONE_VALID_SIM_MUST_BE_PRESENT:
            policy = SimLockMultiSimPolicy.ONE_VALID_SIM_MUST_BE_PRESENT;
            break;
    }
    if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_4)) {
        riljLog("RIL.java - Using IRadio 1.4 or greater");
        android.hardware.radio.V1_4.IRadio radioProxy14 = (android.hardware.radio.V1_4.IRadio) radioProxy;
        // Prepare structure with allowed list, excluded list and priority
        CarrierRestrictionsWithPriority carrierRestrictions = new CarrierRestrictionsWithPriority();
        carrierRestrictions.allowedCarriers = createCarrierRestrictionList(carrierRestrictionRules.getAllowedCarriers());
        carrierRestrictions.excludedCarriers = createCarrierRestrictionList(carrierRestrictionRules.getExcludedCarriers());
        carrierRestrictions.allowedCarriersPrioritized = (carrierRestrictionRules.getDefaultCarrierRestriction() == CarrierRestrictionRules.CARRIER_RESTRICTION_DEFAULT_NOT_ALLOWED);
        try {
            radioProxy14.setAllowedCarriers_1_4(rr.mSerial, carrierRestrictions, policy);
        } catch (RemoteException | RuntimeException e) {
            handleRadioProxyExceptionForRR(rr, "setAllowedCarriers_1_4", e);
        }
    } else {
        boolean isAllCarriersAllowed = carrierRestrictionRules.isAllCarriersAllowed();
        boolean supported = (isAllCarriersAllowed || (carrierRestrictionRules.getExcludedCarriers().isEmpty() && (carrierRestrictionRules.getDefaultCarrierRestriction() == CarrierRestrictionRules.CARRIER_RESTRICTION_DEFAULT_NOT_ALLOWED)));
        supported = supported && (policy == SimLockMultiSimPolicy.NO_MULTISIM_POLICY);
        if (!supported) {
            // Feature is not supported by IRadio interface
            riljLoge("setAllowedCarriers does not support excluded list on IRadio version" + " less than 1.4");
            if (result != null) {
                AsyncResult.forMessage(result, null, CommandException.fromRilErrno(REQUEST_NOT_SUPPORTED));
                result.sendToTarget();
            }
            return;
        }
        riljLog("RIL.java - Using IRadio 1.3 or lower");
        // Prepare structure with allowed list
        CarrierRestrictions carrierRestrictions = new CarrierRestrictions();
        carrierRestrictions.allowedCarriers = createCarrierRestrictionList(carrierRestrictionRules.getAllowedCarriers());
        try {
            radioProxy.setAllowedCarriers(rr.mSerial, isAllCarriersAllowed, carrierRestrictions);
        } catch (RemoteException | RuntimeException e) {
            handleRadioProxyExceptionForRR(rr, "setAllowedCarriers", e);
        }
    }
}
Also used : CarrierRestrictionsWithPriority(android.hardware.radio.V1_4.CarrierRestrictionsWithPriority) IRadio(android.hardware.radio.V1_0.IRadio) CarrierRestrictions(android.hardware.radio.V1_0.CarrierRestrictions) RemoteException(android.os.RemoteException)

Example 5 with Carrier

use of android.hardware.radio.V1_0.Carrier in project android_frameworks_opt_telephony by LineageOS.

the class DcTrackerTest method testCheckForCompatibleDataConnectionWithDunWhenIdsChange.

// This tests simulates the race case where the sim status change event is triggered, the
// default data connection is attached, and then the carrier config gets changed which bumps
// the database id which we want to ignore when cleaning up connections and matching against
// the dun APN.  Tests b/158908392.
@Test
@SmallTest
public void testCheckForCompatibleDataConnectionWithDunWhenIdsChange() throws Exception {
    // Set dun as a support apn type of FAKE_APN1
    mApnSettingContentProvider.setFakeApn1Types("default,supl,dun");
    // Enable the default apn
    mSimulatedCommands.setDataCallResult(true, createSetupDataCallResult());
    mDct.enableApn(ApnSetting.TYPE_DEFAULT, DcTracker.REQUEST_TYPE_NORMAL, null);
    waitForLastHandlerAction(mDcTrackerTestHandler.getThreadHandler());
    // Load the sim and attach the data connection without firing the carrier changed event
    final String logMsgPrefix = "testCheckForCompatibleDataConnectionWithDunWhenIdsChange: ";
    sendSimStateUpdated(logMsgPrefix);
    sendEventDataConnectionAttached(logMsgPrefix);
    waitForMs(200);
    // Confirm that FAKE_APN1 comes up as a dun candidate
    ApnSetting dunApn = mDct.fetchDunApns().get(0);
    assertEquals(dunApn.getApnName(), FAKE_APN1);
    Map<Integer, ApnContext> apnContexts = mDct.getApnContexts().stream().collect(Collectors.toMap(ApnContext::getApnTypeBitmask, x -> x));
    // Double check that the default apn content is connected while the dun apn context is not
    assertEquals(apnContexts.get(ApnSetting.TYPE_DEFAULT).getState(), DctConstants.State.CONNECTED);
    assertNotEquals(apnContexts.get(ApnSetting.TYPE_DUN).getState(), DctConstants.State.CONNECTED);
    // Change the row ids the same way as what happens when we have old apn values in the
    // carrier table
    mApnSettingContentProvider.setRowIdOffset(100);
    sendCarrierConfigChanged(logMsgPrefix);
    waitForMs(200);
    mDct.enableApn(ApnSetting.TYPE_DUN, DcTracker.REQUEST_TYPE_NORMAL, null);
    waitForLastHandlerAction(mDcTrackerTestHandler.getThreadHandler());
    Map<Integer, ApnContext> apnContextsAfterRowIdsChanged = mDct.getApnContexts().stream().collect(Collectors.toMap(ApnContext::getApnTypeBitmask, x -> x));
    // Make sure that the data connection used earlier wasn't cleaned up and still in use.
    assertEquals(apnContexts.get(ApnSetting.TYPE_DEFAULT).getDataConnection(), apnContextsAfterRowIdsChanged.get(ApnSetting.TYPE_DEFAULT).getDataConnection());
    // Check that the DUN is using the same active data connection
    assertEquals(apnContexts.get(ApnSetting.TYPE_DEFAULT).getDataConnection(), apnContextsAfterRowIdsChanged.get(ApnSetting.TYPE_DUN).getDataConnection());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Telephony(android.provider.Telephony) FlakyTest(androidx.test.filters.FlakyTest) Arrays(java.util.Arrays) ZonedDateTime(java.time.ZonedDateTime) Uri(android.net.Uri) TelephonyTest(com.android.internal.telephony.TelephonyTest) DataProfile(android.telephony.data.DataProfile) PendingIntent(android.app.PendingIntent) NetworkCapabilities(android.net.NetworkCapabilities) LinkProperties(android.net.LinkProperties) IBinder(android.os.IBinder) ContentResolver(android.content.ContentResolver) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TelephonyTestUtils.waitForMs(com.android.internal.telephony.TelephonyTestUtils.waitForMs) Matchers.eq(org.mockito.Matchers.eq) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Handler(android.os.Handler) After(org.junit.After) Map(java.util.Map) PersistableBundle(android.os.PersistableBundle) Matchers.anyInt(org.mockito.Matchers.anyInt) MockContentResolver(android.test.mock.MockContentResolver) Assert.fail(org.junit.Assert.fail) SubscriptionPlan(android.telephony.SubscriptionPlan) CarrierConfigManager(android.telephony.CarrierConfigManager) Mockito.doReturn(org.mockito.Mockito.doReturn) Method(java.lang.reflect.Method) MediumTest(android.test.suitebuilder.annotation.MediumTest) Mockito.clearInvocations(org.mockito.Mockito.clearInvocations) ServiceState(android.telephony.ServiceState) Mockito.atLeastOnce(org.mockito.Mockito.atLeastOnce) IntentFilter(android.content.IntentFilter) NetworkPolicyManager(android.net.NetworkPolicyManager) ISub(com.android.internal.telephony.ISub) Collectors(java.util.stream.Collectors) AccessNetworkType(android.telephony.AccessNetworkConstants.AccessNetworkType) Matchers.any(org.mockito.Matchers.any) Objects(java.util.Objects) NetworkRegistrationInfo(android.telephony.NetworkRegistrationInfo) List(java.util.List) Message(android.os.Message) Assert.assertFalse(org.junit.Assert.assertFalse) Optional(java.util.Optional) ContentValues(android.content.ContentValues) Context(android.content.Context) AccessNetworkConstants(android.telephony.AccessNetworkConstants) ApnSetting(android.telephony.data.ApnSetting) DctConstants(com.android.internal.telephony.DctConstants) SmallTest(android.test.suitebuilder.annotation.SmallTest) Mock(org.mockito.Mock) Pair(android.util.Pair) AsyncResult(android.os.AsyncResult) Intent(android.content.Intent) HashMap(java.util.HashMap) Mockito.spy(org.mockito.Mockito.spy) PhoneConstants(com.android.internal.telephony.PhoneConstants) Matchers.anyString(org.mockito.Matchers.anyString) ArrayList(java.util.ArrayList) Mockito.timeout(org.mockito.Mockito.timeout) Answer(org.mockito.stubbing.Answer) DataService(android.telephony.data.DataService) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ArgumentCaptor(org.mockito.ArgumentCaptor) TelephonyDisplayInfo(android.telephony.TelephonyDisplayInfo) SubscriptionManager(android.telephony.SubscriptionManager) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) TelephonyManager(android.telephony.TelephonyManager) Matchers.anyLong(org.mockito.Matchers.anyLong) Settings(android.provider.Settings) R(com.android.internal.R) SubscriptionInfo(android.telephony.SubscriptionInfo) Cursor(android.database.Cursor) Before(org.junit.Before) Period(java.time.Period) AlarmManager(android.app.AlarmManager) NetworkAgent(android.net.NetworkAgent) Assert.assertTrue(org.junit.Assert.assertTrue) Mockito.times(org.mockito.Mockito.times) TextUtils(android.text.TextUtils) Test(org.junit.Test) Field(java.lang.reflect.Field) NetworkRequest(android.net.NetworkRequest) MockContentProvider(android.test.mock.MockContentProvider) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) Mockito.verify(org.mockito.Mockito.verify) Mockito.never(org.mockito.Mockito.never) SignalStrength(android.telephony.SignalStrength) ApnSettingTest.createApnSetting(com.android.internal.telephony.dataconnection.ApnSettingTest.createApnSetting) Ignore(org.junit.Ignore) HandlerThread(android.os.HandlerThread) MatrixCursor(android.database.MatrixCursor) ServiceInfo(android.content.pm.ServiceInfo) Assert.assertEquals(org.junit.Assert.assertEquals) SetupDataCallResult(android.hardware.radio.V1_0.SetupDataCallResult) Matchers.anyString(org.mockito.Matchers.anyString) ApnSetting(android.telephony.data.ApnSetting) ApnSettingTest.createApnSetting(com.android.internal.telephony.dataconnection.ApnSettingTest.createApnSetting) FlakyTest(androidx.test.filters.FlakyTest) TelephonyTest(com.android.internal.telephony.TelephonyTest) MediumTest(android.test.suitebuilder.annotation.MediumTest) SmallTest(android.test.suitebuilder.annotation.SmallTest) Test(org.junit.Test) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Aggregations

Carrier (android.hardware.radio.V1_0.Carrier)3 CarrierIdentifier (android.service.carrier.CarrierIdentifier)3 ArrayList (java.util.ArrayList)3 CarrierRestrictions (android.hardware.radio.V1_0.CarrierRestrictions)2 IRadio (android.hardware.radio.V1_0.IRadio)2 RemoteException (android.os.RemoteException)2 FlakyTest (androidx.test.filters.FlakyTest)2 Test (org.junit.Test)2 AlarmManager (android.app.AlarmManager)1 PendingIntent (android.app.PendingIntent)1 ContentResolver (android.content.ContentResolver)1 ContentValues (android.content.ContentValues)1 Context (android.content.Context)1 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 ServiceInfo (android.content.pm.ServiceInfo)1 Cursor (android.database.Cursor)1 MatrixCursor (android.database.MatrixCursor)1 SetupDataCallResult (android.hardware.radio.V1_0.SetupDataCallResult)1 CarrierRestrictionsWithPriority (android.hardware.radio.V1_4.CarrierRestrictionsWithPriority)1