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);
}
}
}
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;
}
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));
}
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);
}
}
}
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());
}
Aggregations