Search in sources :

Example 6 with DataProfile

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

the class RIL method setDataProfile.

@Override
public void setDataProfile(DataProfile[] dps, boolean isRoaming, Message result) {
    IRadio radioProxy = getRadioProxy(result);
    if (radioProxy != null) {
        RILRequest rr = null;
        try {
            if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_5)) {
                // V1.5
                android.hardware.radio.V1_5.IRadio radioProxy15 = (android.hardware.radio.V1_5.IRadio) radioProxy;
                rr = obtainRequest(RIL_REQUEST_SET_DATA_PROFILE, result, mRILDefaultWorkSource);
                ArrayList<android.hardware.radio.V1_5.DataProfileInfo> dpis = new ArrayList<>();
                for (DataProfile dp : dps) {
                    dpis.add(convertToHalDataProfile15(dp));
                }
                if (RILJ_LOGD) {
                    riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) + " with data profiles : ");
                    for (DataProfile profile : dps) {
                        riljLog(profile.toString());
                    }
                }
                radioProxy15.setDataProfile_1_5(rr.mSerial, dpis);
            } else if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_4)) {
                // V1.4
                android.hardware.radio.V1_4.IRadio radioProxy14 = (android.hardware.radio.V1_4.IRadio) radioProxy;
                rr = obtainRequest(RIL_REQUEST_SET_DATA_PROFILE, result, mRILDefaultWorkSource);
                ArrayList<android.hardware.radio.V1_4.DataProfileInfo> dpis = new ArrayList<>();
                for (DataProfile dp : dps) {
                    dpis.add(convertToHalDataProfile14(dp));
                }
                if (RILJ_LOGD) {
                    riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) + " with data profiles : ");
                    for (DataProfile profile : dps) {
                        riljLog(profile.toString());
                    }
                }
                radioProxy14.setDataProfile_1_4(rr.mSerial, dpis);
            } else {
                // V1.0, 1.1, 1,2 and 1.3
                ArrayList<android.hardware.radio.V1_0.DataProfileInfo> dpis = new ArrayList<>();
                for (DataProfile dp : dps) {
                    // (a.k.a modem cognitive) bit set to true.
                    if (dp.isPersistent()) {
                        dpis.add(convertToHalDataProfile10(dp));
                    }
                }
                if (!dpis.isEmpty()) {
                    rr = obtainRequest(RIL_REQUEST_SET_DATA_PROFILE, result, mRILDefaultWorkSource);
                    if (RILJ_LOGD) {
                        riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) + " with data profiles : ");
                        for (DataProfile profile : dps) {
                            riljLog(profile.toString());
                        }
                    }
                    radioProxy.setDataProfile(rr.mSerial, dpis, isRoaming);
                }
            }
        } catch (RemoteException | RuntimeException e) {
            handleRadioProxyExceptionForRR(rr, "setDataProfile", e);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) IRadio(android.hardware.radio.V1_0.IRadio) DataProfile(android.telephony.data.DataProfile) RemoteException(android.os.RemoteException)

Example 7 with DataProfile

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

the class DataConnection method connect.

/**
 * Begin setting up a data connection, calls setupDataCall
 * and the ConnectionParams will be returned with the
 * EVENT_SETUP_DATA_CONNECTION_DONE
 *
 * @param cp is the connection parameters
 *
 * @return Fail cause if failed to setup data connection. {@link DataFailCause#NONE} if success.
 */
@DataFailureCause
private int connect(ConnectionParams cp) {
    log("connect: carrier='" + mApnSetting.getEntryName() + "' APN='" + mApnSetting.getApnName() + "' proxy='" + mApnSetting.getProxyAddressAsString() + "' port='" + mApnSetting.getProxyPort() + "'");
    if (cp.mApnContext != null)
        cp.mApnContext.requestLog("DataConnection.connect");
    // Check if we should fake an error.
    if (mDcTesterFailBringUpAll.getDcFailBringUp().mCounter > 0) {
        DataCallResponse response = new DataCallResponse.Builder().setCause(mDcTesterFailBringUpAll.getDcFailBringUp().mFailCause).setSuggestedRetryTime(mDcTesterFailBringUpAll.getDcFailBringUp().mSuggestedRetryTime).setMtuV4(PhoneConstants.UNSET_MTU).setMtuV6(PhoneConstants.UNSET_MTU).build();
        Message msg = obtainMessage(EVENT_SETUP_DATA_CONNECTION_DONE, cp);
        AsyncResult.forMessage(msg, response, null);
        sendMessage(msg);
        if (DBG) {
            log("connect: FailBringUpAll=" + mDcTesterFailBringUpAll.getDcFailBringUp() + " send error response=" + response);
        }
        mDcTesterFailBringUpAll.getDcFailBringUp().mCounter -= 1;
        return DataFailCause.NONE;
    }
    mCreateTime = -1;
    mLastFailTime = -1;
    mLastFailCause = DataFailCause.NONE;
    Message msg = obtainMessage(EVENT_SETUP_DATA_CONNECTION_DONE, cp);
    msg.obj = cp;
    DataProfile dp = DcTracker.createDataProfile(mApnSetting, cp.mProfileId, cp.mIsPreferredApn);
    // We need to use the actual modem roaming state instead of the framework roaming state
    // here. This flag is only passed down to ril_service for picking the correct protocol (for
    // old modem backward compatibility).
    boolean isModemRoaming = mPhone.getServiceState().getDataRoamingFromRegistration();
    // If the apn is NOT metered, we will allow data roaming regardless of the setting.
    boolean isUnmeteredApnType = !ApnSettingUtils.isMeteredApnType(cp.mApnContext.getApnTypeBitmask(), mPhone);
    // Set this flag to true if the user turns on data roaming. Or if we override the roaming
    // state in framework, we should set this flag to true as well so the modem will not reject
    // the data call setup (because the modem actually thinks the device is roaming).
    boolean allowRoaming = mPhone.getDataRoamingEnabled() || (isModemRoaming && (!mPhone.getServiceState().getDataRoaming() || isUnmeteredApnType));
    if (DBG) {
        log("allowRoaming=" + allowRoaming + ", mPhone.getDataRoamingEnabled()=" + mPhone.getDataRoamingEnabled() + ", isModemRoaming=" + isModemRoaming + ", mPhone.getServiceState().getDataRoaming()=" + mPhone.getServiceState().getDataRoaming() + ", isUnmeteredApnType=" + isUnmeteredApnType);
    }
    // Check if this data setup is a handover.
    LinkProperties linkProperties = null;
    int reason = DataService.REQUEST_REASON_NORMAL;
    if (cp.mRequestType == DcTracker.REQUEST_TYPE_HANDOVER) {
        // If this is a data setup for handover, we need to pass the link properties
        // of the existing data connection to the modem.
        DcTracker dcTracker = mPhone.getDcTracker(getHandoverSourceTransport());
        if (dcTracker == null || cp.mApnContext == null) {
            loge("connect: Handover failed. dcTracker=" + dcTracker + ", apnContext=" + cp.mApnContext);
            return DataFailCause.HANDOVER_FAILED;
        }
        DataConnection dc = dcTracker.getDataConnectionByApnType(cp.mApnContext.getApnType());
        if (dc == null) {
            loge("connect: Can't find data connection for handover.");
            return DataFailCause.HANDOVER_FAILED;
        }
        // Preserve the potential network agent from the source data connection. The ownership
        // is not transferred at this moment.
        mHandoverSourceNetworkAgent = dc.getNetworkAgent();
        if (mHandoverSourceNetworkAgent == null) {
            loge("Cannot get network agent from the source dc " + dc.getName());
            return DataFailCause.HANDOVER_FAILED;
        }
        linkProperties = dc.getLinkProperties();
        if (linkProperties == null || linkProperties.getLinkAddresses().isEmpty()) {
            loge("connect: Can't find link properties of handover data connection. dc=" + dc);
            return DataFailCause.HANDOVER_FAILED;
        }
        mHandoverLocalLog.log("Handover started. Preserved the agent.");
        log("Get the handover source network agent: " + mHandoverSourceNetworkAgent);
        dc.setHandoverState(HANDOVER_STATE_BEING_TRANSFERRED);
        reason = DataService.REQUEST_REASON_HANDOVER;
    }
    mDataServiceManager.setupDataCall(ServiceState.rilRadioTechnologyToAccessNetworkType(cp.mRilRat), dp, isModemRoaming, allowRoaming, reason, linkProperties, msg);
    TelephonyMetrics.getInstance().writeSetupDataCall(mPhone.getPhoneId(), cp.mRilRat, dp.getProfileId(), dp.getApn(), dp.getProtocolType());
    return DataFailCause.NONE;
}
Also used : DataCallResponse(android.telephony.data.DataCallResponse) DataProfile(android.telephony.data.DataProfile) Message(android.os.Message) LinkProperties(android.net.LinkProperties) DataFailureCause(android.telephony.Annotation.DataFailureCause)

Example 8 with DataProfile

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

the class DcTracker method setDataProfilesAsNeeded.

protected void setDataProfilesAsNeeded() {
    if (DBG)
        log("setDataProfilesAsNeeded");
    ArrayList<DataProfile> dataProfileList = new ArrayList<>();
    int preferredApnSetId = getPreferredApnSetId();
    for (ApnSetting apn : mAllApnSettings) {
        if (apn.getApnSetId() == Telephony.Carriers.MATCH_ALL_APN_SET_ID || preferredApnSetId == apn.getApnSetId()) {
            DataProfile dp = createDataProfile(apn, apn.equals(getPreferredApn()));
            if (!dataProfileList.contains(dp)) {
                dataProfileList.add(dp);
            }
        } else {
            if (VDBG) {
                log("setDataProfilesAsNeeded: APN set id " + apn.getApnSetId() + " does not match the preferred set id " + preferredApnSetId);
            }
        }
    }
    // send it to the modem.
    if (!dataProfileList.isEmpty() && (dataProfileList.size() != mLastDataProfileList.size() || !mLastDataProfileList.containsAll(dataProfileList))) {
        mDataServiceManager.setDataProfile(dataProfileList, mPhone.getServiceState().getDataRoamingFromRegistration(), null);
    }
}
Also used : DataProfile(android.telephony.data.DataProfile) ArrayList(java.util.ArrayList) ApnSetting(android.telephony.data.ApnSetting)

Example 9 with DataProfile

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

the class RILTest method testSetInitialAttachApn.

@FlakyTest
@Test
public void testSetInitialAttachApn() throws Exception {
    ApnSetting apnSetting = ApnSetting.makeApnSetting(-1, "22210", "Vodafone IT", "web.omnitel.it", null, -1, null, null, -1, "", "", 0, ApnSetting.TYPE_DUN, ApnSetting.PROTOCOL_IP, ApnSetting.PROTOCOL_IP, true, 0, 0, false, 0, 0, 0, 0, -1, "");
    DataProfile dataProfile = DcTracker.createDataProfile(apnSetting, apnSetting.getProfileId(), false);
    boolean isRoaming = false;
    mRILUnderTest.setInitialAttachApn(dataProfile, isRoaming, obtainMessage());
    verify(mRadioProxy).setInitialAttachApn(mSerialNumberCaptor.capture(), eq((DataProfileInfo) invokeMethod(mRILInstance, "convertToHalDataProfile10", new Class<?>[] { DataProfile.class }, new Object[] { dataProfile })), eq(dataProfile.isPersistent()), eq(isRoaming));
    verifyRILResponse(mRILUnderTest, mSerialNumberCaptor.getValue(), RIL_REQUEST_SET_INITIAL_ATTACH_APN);
}
Also used : DataProfile(android.telephony.data.DataProfile) DataProfileInfo(android.hardware.radio.V1_0.DataProfileInfo) ApnSetting(android.telephony.data.ApnSetting) FlakyTest(androidx.test.filters.FlakyTest) FlakyTest(androidx.test.filters.FlakyTest) Test(org.junit.Test)

Example 10 with DataProfile

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

the class DcTrackerTest method testUserDisableData.

@Test
@MediumTest
@Ignore
@FlakyTest
public void testUserDisableData() throws Exception {
    // step 1: setup two DataCalls one for Metered: default, another one for Non-metered: IMS
    // set Default and MMS to be metered in the CarrierConfigManager
    mBundle.putStringArray(CarrierConfigManager.KEY_CARRIER_METERED_APN_TYPES_STRINGS, new String[] { PhoneConstants.APN_TYPE_DEFAULT, PhoneConstants.APN_TYPE_MMS });
    mDct.enableApn(ApnSetting.TYPE_IMS, DcTracker.REQUEST_TYPE_NORMAL, null);
    mDct.enableApn(ApnSetting.TYPE_DEFAULT, DcTracker.REQUEST_TYPE_NORMAL, null);
    sendInitializationEvents();
    ArgumentCaptor<DataProfile> dpCaptor = ArgumentCaptor.forClass(DataProfile.class);
    verify(mSimulatedCommandsVerifier, times(2)).setupDataCall(eq(AccessNetworkType.EUTRAN), dpCaptor.capture(), eq(false), eq(false), eq(DataService.REQUEST_REASON_NORMAL), any(), any(Message.class));
    verifyDataProfile(dpCaptor.getValue(), FAKE_APN1, 0, 5, 1, NETWORK_TYPE_LTE_BITMASK);
    logd("Sending DATA_DISABLED_CMD");
    doReturn(false).when(mDataEnabledSettings).isDataEnabled();
    doReturn(false).when(mDataEnabledSettings).isDataEnabled(anyInt());
    AsyncResult ar = new AsyncResult(null, new Pair<>(false, DataEnabledSettings.REASON_USER_DATA_ENABLED), null);
    mDct.sendMessage(mDct.obtainMessage(DctConstants.EVENT_DATA_ENABLED_CHANGED, ar));
    waitForLastHandlerAction(mDcTrackerTestHandler.getThreadHandler());
    // Data connection is running on a different thread. Have to wait.
    waitForMs(200);
    // expected tear down all metered DataConnections
    verify(mSimulatedCommandsVerifier, times(1)).deactivateDataCall(eq(DataService.REQUEST_REASON_NORMAL), anyInt(), any(Message.class));
    assertTrue(mDct.isAnyDataConnected());
    assertEquals(DctConstants.State.IDLE, mDct.getState(PhoneConstants.APN_TYPE_DEFAULT));
    assertEquals(DctConstants.State.CONNECTED, mDct.getState(PhoneConstants.APN_TYPE_IMS));
}
Also used : DataProfile(android.telephony.data.DataProfile) Message(android.os.Message) AsyncResult(android.os.AsyncResult) Ignore(org.junit.Ignore) FlakyTest(androidx.test.filters.FlakyTest) 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) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Aggregations

DataProfile (android.telephony.data.DataProfile)15 SmallTest (android.test.suitebuilder.annotation.SmallTest)10 FlakyTest (androidx.test.filters.FlakyTest)9 Test (org.junit.Test)9 Message (android.os.Message)8 MediumTest (android.test.suitebuilder.annotation.MediumTest)7 TelephonyTest (com.android.internal.telephony.TelephonyTest)7 ContentResolver (android.content.ContentResolver)4 SignalStrength (android.telephony.SignalStrength)4 MockContentResolver (android.test.mock.MockContentResolver)4 AsyncResult (android.os.AsyncResult)3 DataProfileInfo (android.hardware.radio.V1_0.DataProfileInfo)2 ApnSetting (android.telephony.data.ApnSetting)2 ArrayList (java.util.ArrayList)2 Ignore (org.junit.Ignore)2 IRadio (android.hardware.radio.V1_0.IRadio)1 SetupDataCallResult (android.hardware.radio.V1_0.SetupDataCallResult)1 LinkProperties (android.net.LinkProperties)1 RemoteException (android.os.RemoteException)1 DataFailureCause (android.telephony.Annotation.DataFailureCause)1