Search in sources :

Example 16 with ApnSetting

use of android.telephony.data.ApnSetting in project android_frameworks_opt_telephony by LineageOS.

the class RetryManagerTest method testRetryManagerApnPermanentFailedAll.

/**
 * Test the permanent fail scenario with two APN all failed
 */
@Test
@SmallTest
public void testRetryManagerApnPermanentFailedAll() throws Exception {
    mBundle.putStringArray(CarrierConfigManager.KEY_CARRIER_DATA_CALL_RETRY_CONFIG_STRINGS, new String[] { "default:1000,4000,7000,9000", "mms:1234,4123" });
    ArrayList<ApnSetting> waitingApns = new ArrayList<ApnSetting>();
    ApnSetting myApn1 = ApnSetting.makeApnSetting(mApn1);
    ApnSetting myApn2 = ApnSetting.makeApnSetting(mApn2);
    waitingApns.add(myApn1);
    waitingApns.add(myApn2);
    RetryManager rm = new RetryManager(mPhone, "default");
    rm.setWaitingApns(waitingApns);
    ApnSetting nextApn = rm.getNextApnSetting();
    assertTrue(nextApn.equals(mApn1));
    long delay = rm.getDelayForNextApn(false);
    assertEquals(20000, delay);
    nextApn = rm.getNextApnSetting();
    assertTrue(nextApn.equals(mApn2));
    delay = rm.getDelayForNextApn(false);
    assertEquals(1000, delay);
    nextApn = rm.getNextApnSetting();
    assertTrue(nextApn.equals(mApn1));
    delay = rm.getDelayForNextApn(false);
    assertEquals(20000, delay);
    rm.markApnPermanentFailed(myApn1);
    nextApn = rm.getNextApnSetting();
    assertTrue(nextApn.equals(mApn2));
    delay = rm.getDelayForNextApn(false);
    assertEquals(4000, delay);
    nextApn = rm.getNextApnSetting();
    assertTrue(nextApn.equals(mApn2));
    delay = rm.getDelayForNextApn(false);
    assertEquals(7000, delay);
    rm.markApnPermanentFailed(myApn2);
    nextApn = rm.getNextApnSetting();
    assertTrue(nextApn == null);
    nextApn = rm.getNextApnSetting();
    assertTrue(nextApn == null);
}
Also used : RetryManager(com.android.internal.telephony.RetryManager) ArrayList(java.util.ArrayList) ApnSetting(android.telephony.data.ApnSetting) SmallTest(android.test.suitebuilder.annotation.SmallTest) TelephonyTest(com.android.internal.telephony.TelephonyTest) Test(org.junit.Test) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 17 with ApnSetting

use of android.telephony.data.ApnSetting in project android_frameworks_opt_telephony by LineageOS.

the class RetryManager method setWaitingApns.

/**
 * Set waiting APNs for retrying in case needed.
 * @param waitingApns Waiting APN list
 */
public void setWaitingApns(ArrayList<ApnSetting> waitingApns) {
    if (waitingApns == null) {
        log("No waiting APNs provided");
        return;
    }
    mWaitingApns = waitingApns;
    // Since we replace the entire waiting APN list, we need to re-config this retry manager.
    configureRetry();
    for (ApnSetting apn : mWaitingApns) {
        apn.setPermanentFailed(false);
    }
    log("Setting " + mWaitingApns.size() + " waiting APNs.");
    if (VDBG) {
        for (int i = 0; i < mWaitingApns.size(); i++) {
            log("  [" + i + "]:" + mWaitingApns.get(i));
        }
    }
}
Also used : ApnSetting(android.telephony.data.ApnSetting)

Example 18 with ApnSetting

use of android.telephony.data.ApnSetting in project android_frameworks_opt_telephony by LineageOS.

the class DcTracker method buildWaitingApns.

/**
 * Build a list of APNs to be used to create PDP's.
 *
 * @param requestedApnType
 * @return waitingApns list to be used to create PDP
 *          error when waitingApns.isEmpty()
 */
private ArrayList<ApnSetting> buildWaitingApns(String requestedApnType, int radioTech) {
    if (DBG)
        log("buildWaitingApns: E requestedApnType=" + requestedApnType);
    ArrayList<ApnSetting> apnList = new ArrayList<ApnSetting>();
    int requestedApnTypeBitmask = ApnSetting.getApnTypesBitmaskFromString(requestedApnType);
    if (requestedApnTypeBitmask == ApnSetting.TYPE_DUN) {
        ArrayList<ApnSetting> dunApns = fetchDunApns();
        if (dunApns.size() > 0) {
            for (ApnSetting dun : dunApns) {
                apnList.add(dun);
                if (DBG)
                    log("buildWaitingApns: X added APN_TYPE_DUN apnList=" + apnList);
            }
            return apnList;
        }
    }
    String operator = mPhone.getOperatorNumeric();
    // This is a workaround for a bug (7305641) where we don't failover to other
    // suitable APNs if our preferred APN fails.  On prepaid ATT sims we need to
    // failover to a provisioning APN, but once we've used their default data
    // connection we are locked to it for life.  This change allows ATT devices
    // to say they don't want to use preferred at all.
    boolean usePreferred = true;
    try {
        usePreferred = !mPhone.getContext().getResources().getBoolean(com.android.internal.R.bool.config_dontPreferApn);
    } catch (Resources.NotFoundException e) {
        if (DBG)
            log("buildWaitingApns: usePreferred NotFoundException set to true");
        usePreferred = true;
    }
    if (usePreferred) {
        mPreferredApn = getPreferredApn();
    }
    if (DBG) {
        log("buildWaitingApns: usePreferred=" + usePreferred + " canSetPreferApn=" + mCanSetPreferApn + " mPreferredApn=" + mPreferredApn + " operator=" + operator + " radioTech=" + radioTech);
    }
    if (usePreferred && mCanSetPreferApn && mPreferredApn != null && mPreferredApn.canHandleType(requestedApnTypeBitmask)) {
        if (DBG) {
            log("buildWaitingApns: Preferred APN:" + operator + ":" + mPreferredApn.getOperatorNumeric() + ":" + mPreferredApn);
        }
        if (mPreferredApn.getOperatorNumeric().equals(operator)) {
            if (mPreferredApn.canSupportNetworkType(ServiceState.rilRadioTechnologyToNetworkType(radioTech))) {
                apnList.add(mPreferredApn);
                if (DBG)
                    log("buildWaitingApns: X added preferred apnList=" + apnList);
                return apnList;
            }
        }
        if (DBG)
            log("buildWaitingApns: no preferred APN");
        setPreferredApn(-1);
        mPreferredApn = null;
    }
    if (DBG)
        log("buildWaitingApns: mAllApnSettings=" + mAllApnSettings);
    int preferredApnSetId = getPreferredApnSetId();
    for (ApnSetting apn : mAllApnSettings) {
        if (apn.canHandleType(requestedApnTypeBitmask)) {
            if (apn.canSupportNetworkType(ServiceState.rilRadioTechnologyToNetworkType(radioTech))) {
                if (apn.getApnSetId() == Telephony.Carriers.MATCH_ALL_APN_SET_ID || preferredApnSetId == apn.getApnSetId()) {
                    if (VDBG)
                        log("buildWaitingApns: adding apn=" + apn);
                    apnList.add(apn);
                } else {
                    log("buildWaitingApns: APN set id " + apn.getApnSetId() + " does not match the preferred set id " + preferredApnSetId);
                }
            } else {
                if (DBG) {
                    log("buildWaitingApns: networkTypeBitmask:" + apn.getNetworkTypeBitmask() + " does not include radioTech:" + ServiceState.rilRadioTechnologyToString(radioTech));
                }
            }
        } else if (VDBG) {
            log("buildWaitingApns: couldn't handle requested ApnType=" + requestedApnType);
        }
    }
    if (DBG)
        log("buildWaitingApns: " + apnList.size() + " APNs in the list: " + apnList);
    return apnList;
}
Also used : ArrayList(java.util.ArrayList) Resources(android.content.res.Resources) ApnSetting(android.telephony.data.ApnSetting)

Example 19 with ApnSetting

use of android.telephony.data.ApnSetting in project android_frameworks_opt_telephony by LineageOS.

the class DcTracker method getState.

/**
 * Returns {@link DctConstants.State} based on the state of the {@link DataConnection} that
 * contains a {@link ApnSetting} that supported the given apn type {@code anpType}.
 *
 * <p>
 * Assumes there is less than one {@link ApnSetting} can support the given apn type.
 */
public DctConstants.State getState(String apnType) {
    DctConstants.State state = DctConstants.State.IDLE;
    final int apnTypeBitmask = ApnSetting.getApnTypesBitmaskFromString(apnType);
    for (DataConnection dc : mDataConnections.values()) {
        ApnSetting apnSetting = dc.getApnSetting();
        if (apnSetting != null && apnSetting.canHandleType(apnTypeBitmask)) {
            if (dc.isActive()) {
                state = getBetterConnectionState(state, DctConstants.State.CONNECTED);
            } else if (dc.isActivating()) {
                state = getBetterConnectionState(state, DctConstants.State.CONNECTING);
            } else if (dc.isInactive()) {
                state = getBetterConnectionState(state, DctConstants.State.IDLE);
            } else if (dc.isDisconnecting()) {
                state = getBetterConnectionState(state, DctConstants.State.DISCONNECTING);
            }
        }
    }
    return state;
}
Also used : DctConstants(com.android.internal.telephony.DctConstants) ApnSetting(android.telephony.data.ApnSetting)

Example 20 with ApnSetting

use of android.telephony.data.ApnSetting in project android_frameworks_opt_telephony by LineageOS.

the class DcTracker method checkForCompatibleDataConnection.

private DataConnection checkForCompatibleDataConnection(ApnContext apnContext, ApnSetting nextApn) {
    int apnType = apnContext.getApnTypeBitmask();
    ArrayList<ApnSetting> dunSettings = null;
    if (ApnSetting.TYPE_DUN == apnType) {
        dunSettings = fetchDunApns();
    }
    if (DBG) {
        log("checkForCompatibleDataConnection: apnContext=" + apnContext);
    }
    DataConnection potentialDc = null;
    for (DataConnection curDc : mDataConnections.values()) {
        if (curDc != null) {
            ApnSetting apnSetting = curDc.getApnSetting();
            log("apnSetting: " + apnSetting);
            if (dunSettings != null && dunSettings.size() > 0) {
                for (ApnSetting dunSetting : dunSettings) {
                    // when calculating dun candidates.
                    if (areCompatible(dunSetting, apnSetting)) {
                        if (curDc.isActive()) {
                            if (DBG) {
                                log("checkForCompatibleDataConnection:" + " found dun conn=" + curDc);
                            }
                            return curDc;
                        } else if (curDc.isActivating()) {
                            potentialDc = curDc;
                        }
                    }
                }
            } else if (apnSetting != null && apnSetting.canHandleType(apnType)) {
                if (curDc.isActive()) {
                    if (DBG) {
                        log("checkForCompatibleDataConnection:" + " found canHandle conn=" + curDc);
                    }
                    return curDc;
                } else if (curDc.isActivating() || apnSetting.equals(nextApn)) {
                    potentialDc = curDc;
                }
            }
        }
    }
    if (DBG) {
        log("checkForCompatibleDataConnection: potential dc=" + potentialDc);
    }
    return potentialDc;
}
Also used : ApnSetting(android.telephony.data.ApnSetting)

Aggregations

ApnSetting (android.telephony.data.ApnSetting)50 Test (org.junit.Test)30 SmallTest (android.test.suitebuilder.annotation.SmallTest)28 TelephonyTest (com.android.internal.telephony.TelephonyTest)28 ArrayList (java.util.ArrayList)23 RetryManager (com.android.internal.telephony.RetryManager)19 Cursor (android.database.Cursor)5 FlakyTest (androidx.test.filters.FlakyTest)4 ApnSettingTest.createApnSetting (com.android.internal.telephony.dataconnection.ApnSettingTest.createApnSetting)4 ContentResolver (android.content.ContentResolver)3 Uri (android.net.Uri)3 Message (android.os.Message)3 DataProfile (android.telephony.data.DataProfile)3 MediumTest (android.test.suitebuilder.annotation.MediumTest)3 Matchers.anyString (org.mockito.Matchers.anyString)3 NonNull (android.annotation.NonNull)2 PendingIntent (android.app.PendingIntent)2 ContentValues (android.content.ContentValues)2 Intent (android.content.Intent)2 IntentFilter (android.content.IntentFilter)2