Search in sources :

Example 21 with ApnSetting

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

the class DcTracker method shouldCleanUpConnection.

boolean shouldCleanUpConnection(ApnContext apnContext, boolean disableMeteredOnly, boolean singlePdn) {
    if (apnContext == null)
        return false;
    // If APN setting is not null and the reason is single PDN arbitration, clean up connection.
    ApnSetting apnSetting = apnContext.getApnSetting();
    if (apnSetting != null && singlePdn)
        return true;
    // If meteredOnly is false, clean up all connections.
    if (!disableMeteredOnly)
        return true;
    // If meteredOnly is true, and apnSetting is null or it's un-metered, no need to clean up.
    if (apnSetting == null || !ApnSettingUtils.isMetered(apnSetting, mPhone))
        return false;
    boolean isRoaming = mPhone.getServiceState().getDataRoaming();
    boolean isDataRoamingDisabled = !getDataRoamingEnabled();
    boolean isDataDisabled = !mDataEnabledSettings.isDataEnabled(apnSetting.getApnTypeBitmask());
    // Should clean up if its data is disabled, or data roaming is disabled while roaming.
    return isDataDisabled || (isRoaming && isDataRoamingDisabled);
}
Also used : ApnSetting(android.telephony.data.ApnSetting)

Example 22 with ApnSetting

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

the class DcTracker method trySetupData.

private boolean trySetupData(ApnContext apnContext, @RequestNetworkType int requestType) {
    if (mPhone.getSimulatedRadioControl() != null) {
        // Assume data is connected on the simulator
        // FIXME  this can be improved
        apnContext.setState(DctConstants.State.CONNECTED);
        mPhone.notifyDataConnection(apnContext.getApnType());
        log("trySetupData: X We're on the simulator; assuming connected retValue=true");
        return true;
    }
    DataConnectionReasons dataConnectionReasons = new DataConnectionReasons();
    boolean isDataAllowed = isDataAllowed(apnContext, requestType, dataConnectionReasons);
    String logStr = "trySetupData for APN type " + apnContext.getApnType() + ", reason: " + apnContext.getReason() + ", requestType=" + requestTypeToString(requestType) + ". " + dataConnectionReasons.toString();
    if (DBG)
        log(logStr);
    apnContext.requestLog(logStr);
    if (isDataAllowed) {
        if (apnContext.getState() == DctConstants.State.FAILED) {
            String str = "trySetupData: make a FAILED ApnContext IDLE so its reusable";
            if (DBG)
                log(str);
            apnContext.requestLog(str);
            apnContext.setState(DctConstants.State.IDLE);
        }
        int radioTech = getDataRat();
        if (radioTech == ServiceState.RIL_RADIO_TECHNOLOGY_UNKNOWN && mPhone.getServiceState().getState() == ServiceState.STATE_IN_SERVICE) {
            radioTech = getVoiceRat();
        }
        log("service state=" + mPhone.getServiceState());
        apnContext.setConcurrentVoiceAndDataAllowed(mPhone.getServiceStateTracker().isConcurrentVoiceAndDataAllowed());
        if (apnContext.getState() == DctConstants.State.IDLE) {
            ArrayList<ApnSetting> waitingApns = buildWaitingApns(apnContext.getApnType(), radioTech);
            if (waitingApns.isEmpty()) {
                ApnSetting apn = apnContext != null ? apnContext.getApnSetting() : null;
                mPhone.notifyDataConnectionFailed(apnContext.getApnType(), apn != null ? apn.getApnName() : null, DataFailCause.MISSING_UNKNOWN_APN);
                String str = "trySetupData: X No APN found retValue=false";
                if (DBG)
                    log(str);
                apnContext.requestLog(str);
                return false;
            } else {
                apnContext.setWaitingApns(waitingApns);
                if (DBG) {
                    log("trySetupData: Create from mAllApnSettings : " + apnListToString(mAllApnSettings));
                }
            }
        }
        boolean retValue = setupData(apnContext, radioTech, requestType);
        if (DBG)
            log("trySetupData: X retValue=" + retValue);
        return retValue;
    } else {
        StringBuilder str = new StringBuilder();
        str.append("trySetupData failed. apnContext = [type=" + apnContext.getApnType() + ", mState=" + apnContext.getState() + ", apnEnabled=" + apnContext.isEnabled() + ", mDependencyMet=" + apnContext.isDependencyMet() + "] ");
        if (!mDataEnabledSettings.isDataEnabled()) {
            str.append("isDataEnabled() = false. " + mDataEnabledSettings);
        }
        // in RETRYING forever.
        if (apnContext.getState() == DctConstants.State.RETRYING) {
            apnContext.setState(DctConstants.State.FAILED);
            str.append(" Stop retrying.");
        }
        if (DBG)
            log(str.toString());
        apnContext.requestLog(str.toString());
        return false;
    }
}
Also used : ApnSetting(android.telephony.data.ApnSetting)

Example 23 with ApnSetting

use of android.telephony.data.ApnSetting in project robolectric by robolectric.

the class PreciseDataConnectionStateBuilderTest method build_preciseDataConnectionState.

@Test
public void build_preciseDataConnectionState() {
    ApnSetting apnSetting = new ApnSetting.Builder().setApnName("apnName").build();
    PreciseDataConnectionState state = PreciseDataConnectionStateBuilder.newBuilder().setDataState(TelephonyManager.DATA_DISCONNECTED).setNetworkType(TelephonyManager.NETWORK_TYPE_LTE).setApnSetting(apnSetting).setDataFailCause(DataFailCause.IMEI_NOT_ACCEPTED).build();
    assertThat(state).isNotNull();
    assertThat(state.getState()).isEqualTo(TelephonyManager.DATA_DISCONNECTED);
    assertThat(state.getNetworkType()).isEqualTo(TelephonyManager.NETWORK_TYPE_LTE);
    assertThat(state.getLastCauseCode()).isEqualTo(DataFailCause.IMEI_NOT_ACCEPTED);
    assertThat(state.getApnSetting()).isEqualTo(apnSetting);
}
Also used : ApnSetting(android.telephony.data.ApnSetting) PreciseDataConnectionState(android.telephony.PreciseDataConnectionState) Test(org.junit.Test)

Example 24 with ApnSetting

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

the class DcTracker method dedupeApnSettings.

private void dedupeApnSettings() {
    ArrayList<ApnSetting> resultApns = new ArrayList<ApnSetting>();
    // coalesce APNs if they are similar enough to prevent
    // us from bringing up two data calls with the same interface
    int i = 0;
    while (i < mAllApnSettings.size() - 1) {
        ApnSetting first = mAllApnSettings.get(i);
        ApnSetting second = null;
        int j = i + 1;
        while (j < mAllApnSettings.size()) {
            second = mAllApnSettings.get(j);
            if (first.similar(second)) {
                ApnSetting newApn = mergeApns(first, second);
                mAllApnSettings.set(i, newApn);
                first = newApn;
                mAllApnSettings.remove(j);
            } else {
                j++;
            }
        }
        i++;
    }
}
Also used : ArrayList(java.util.ArrayList) ApnSetting(android.telephony.data.ApnSetting)

Example 25 with ApnSetting

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

the class DcTracker method fetchDunApns.

/**
 * Fetch the DUN apns
 * @return a list of DUN ApnSetting objects
 */
@VisibleForTesting
@NonNull
public ArrayList<ApnSetting> fetchDunApns() {
    if (mPhone.getServiceState().getRoaming() && !isPreferredApnUserEdited() && getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DISABLE_DUN_APN_WHILE_ROAMING_WITH_PRESET_APN_BOOL)) {
        if (VDBG)
            log("fetchDunApns: Dun apn is not used in roaming network");
        return new ArrayList<ApnSetting>(0);
    }
    int bearer = getDataRat();
    ArrayList<ApnSetting> dunCandidates = new ArrayList<ApnSetting>();
    ArrayList<ApnSetting> retDunSettings = new ArrayList<ApnSetting>();
    // Places to look for tether APN in order: TETHER_DUN_APN setting (to be deprecated soon),
    // APN database
    String apnData = Settings.Global.getString(mResolver, Settings.Global.TETHER_DUN_APN);
    if (!TextUtils.isEmpty(apnData)) {
        dunCandidates.addAll(ApnSetting.arrayFromString(apnData));
        if (VDBG)
            log("fetchDunApns: dunCandidates from Setting: " + dunCandidates);
    }
    if (dunCandidates.isEmpty()) {
        if (!ArrayUtils.isEmpty(mAllApnSettings)) {
            for (ApnSetting apn : mAllApnSettings) {
                if (apn.canHandleType(ApnSetting.TYPE_DUN)) {
                    dunCandidates.add(apn);
                }
            }
            if (VDBG)
                log("fetchDunApns: dunCandidates from database: " + dunCandidates);
        }
    }
    int preferredApnSetId = getPreferredApnSetId();
    for (ApnSetting dunSetting : dunCandidates) {
        if (dunSetting.canSupportNetworkType(ServiceState.rilRadioTechnologyToNetworkType(bearer))) {
            if (preferredApnSetId == dunSetting.getApnSetId()) {
                retDunSettings.add(dunSetting);
            }
        }
    }
    if (VDBG)
        log("fetchDunApns: dunSettings=" + retDunSettings);
    return retDunSettings;
}
Also used : ArrayList(java.util.ArrayList) ApnSetting(android.telephony.data.ApnSetting) VisibleForTesting(com.android.internal.annotations.VisibleForTesting) NonNull(android.annotation.NonNull)

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