Search in sources :

Example 31 with ApnSetting

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

the class DcTracker method getPreferredApnFromDB.

private ApnSetting getPreferredApnFromDB() {
    ApnSetting preferredApn = null;
    Cursor cursor = getPreferredApnCursor(mPhone.getSubId());
    if (cursor != null) {
        if (cursor.getCount() > 0) {
            cursor.moveToFirst();
            preferredApn = ApnSetting.makeApnSetting(cursor);
        }
        cursor.close();
    }
    if (VDBG)
        log("getPreferredApnFromDB: preferredApn=" + preferredApn);
    return preferredApn;
}
Also used : Cursor(android.database.Cursor) ApnSetting(android.telephony.data.ApnSetting)

Example 32 with ApnSetting

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

the class DcTracker method addEmergencyApnSetting.

/**
 * Add the Emergency APN settings to APN settings list
 */
private void addEmergencyApnSetting() {
    if (mEmergencyApn != null) {
        for (ApnSetting apn : mAllApnSettings) {
            if (apn.canHandleType(ApnSetting.TYPE_EMERGENCY)) {
                log("addEmergencyApnSetting - E-APN setting is already present");
                return;
            }
        }
        // list explicitly.
        if (!mAllApnSettings.contains(mEmergencyApn)) {
            mAllApnSettings.add(mEmergencyApn);
            log("Adding emergency APN : " + mEmergencyApn);
            return;
        }
    }
}
Also used : ApnSetting(android.telephony.data.ApnSetting)

Example 33 with ApnSetting

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

the class DcTracker method setDefaultPreferredApnIfNeeded.

private void setDefaultPreferredApnIfNeeded() {
    ApnSetting defaultPreferredApn = null;
    PersistableBundle bundle = getCarrierConfig();
    String defaultPreferredApnName = bundle.getString(CarrierConfigManager.KEY_DEFAULT_PREFERRED_APN_NAME_STRING);
    if (TextUtils.isEmpty(defaultPreferredApnName) || getPreferredApnFromDB() != null) {
        return;
    }
    String selection = Telephony.Carriers.APN + " = \"" + defaultPreferredApnName + "\" AND " + Telephony.Carriers.EDITED_STATUS + " = " + Telephony.Carriers.UNEDITED;
    Cursor cursor = mPhone.getContext().getContentResolver().query(Uri.withAppendedPath(Telephony.Carriers.SIM_APN_URI, "filtered/subId/" + mPhone.getSubId()), null, selection, null, Telephony.Carriers._ID);
    if (cursor != null) {
        if (cursor.getCount() > 0) {
            if (cursor.moveToFirst()) {
                defaultPreferredApn = ApnSetting.makeApnSetting(cursor);
            }
        }
        cursor.close();
    }
    if (defaultPreferredApn != null && defaultPreferredApn.canHandleType(mRequestedApnType)) {
        log("setDefaultPreferredApnIfNeeded: For APN type " + ApnSetting.getApnTypeString(mRequestedApnType) + " found default apnSetting " + defaultPreferredApn);
        setPreferredApn(defaultPreferredApn.getId(), true);
    }
    return;
}
Also used : PersistableBundle(android.os.PersistableBundle) Cursor(android.database.Cursor) ApnSetting(android.telephony.data.ApnSetting)

Example 34 with ApnSetting

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

the class DcTracker method onDataSetupComplete.

/**
 * A SETUP (aka bringUp) has completed, possibly with an error. If
 * there is an error this method will call {@link #onDataSetupCompleteError}.
 */
protected void onDataSetupComplete(ApnContext apnContext, boolean success, int cause, @RequestNetworkType int requestType) {
    int apnType = ApnSetting.getApnTypesBitmaskFromString(apnContext.getApnType());
    List<Message> messageList = mRequestNetworkCompletionMsgs.get(apnType);
    if (messageList != null) {
        for (Message msg : messageList) {
            sendRequestNetworkCompleteMsg(msg, success, mTransportType, requestType, cause);
        }
        messageList.clear();
    }
    if (success) {
        DataConnection dataConnection = apnContext.getDataConnection();
        if (RADIO_TESTS) {
            // Note: To change radio.test.onDSC.null.dcac from command line you need to
            // adb root and adb remount and from the command line you can only change the
            // value to 1 once. To change it a second time you can reboot or execute
            // adb shell stop and then adb shell start. The command line to set the value is:
            // adb shell sqlite3 /data/data/com.android.providers.settings/databases/settings.db "insert into system (name,value) values ('radio.test.onDSC.null.dcac', '1');"
            ContentResolver cr = mPhone.getContext().getContentResolver();
            String radioTestProperty = "radio.test.onDSC.null.dcac";
            if (Settings.System.getInt(cr, radioTestProperty, 0) == 1) {
                log("onDataSetupComplete: " + radioTestProperty + " is true, set dcac to null and reset property to false");
                dataConnection = null;
                Settings.System.putInt(cr, radioTestProperty, 0);
                log("onDataSetupComplete: " + radioTestProperty + "=" + Settings.System.getInt(mPhone.getContext().getContentResolver(), radioTestProperty, -1));
            }
        }
        if (dataConnection == null) {
            log("onDataSetupComplete: no connection to DC, handle as error");
            onDataSetupCompleteError(apnContext, requestType);
        } else {
            ApnSetting apn = apnContext.getApnSetting();
            if (DBG) {
                log("onDataSetupComplete: success apn=" + (apn == null ? "unknown" : apn.getApnName()));
            }
            if (apn != null && !TextUtils.isEmpty(apn.getProxyAddressAsString())) {
                try {
                    int port = apn.getProxyPort();
                    if (port == -1) {
                        port = 8080;
                    }
                    ProxyInfo proxy = ProxyInfo.buildDirectProxy(apn.getProxyAddressAsString(), port);
                    dataConnection.setLinkPropertiesHttpProxy(proxy);
                } catch (NumberFormatException e) {
                    loge("onDataSetupComplete: NumberFormatException making ProxyProperties (" + apn.getProxyPort() + "): " + e);
                }
            }
            // everything is setup
            if (TextUtils.equals(apnContext.getApnType(), PhoneConstants.APN_TYPE_DEFAULT) && mCanSetPreferApn && mPreferredApn == null) {
                if (DBG)
                    log("onDataSetupComplete: PREFERRED APN is null");
                mPreferredApn = apn;
                if (mPreferredApn != null) {
                    setPreferredApn(mPreferredApn.getId());
                }
            }
            // A connection is setup
            apnContext.setState(DctConstants.State.CONNECTED);
            checkDataRoamingStatus(false);
            boolean isProvApn = apnContext.isProvisioningApn();
            final ConnectivityManager cm = (ConnectivityManager) mPhone.getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
            if (mProvisionBroadcastReceiver != null) {
                mPhone.getContext().unregisterReceiver(mProvisionBroadcastReceiver);
                mProvisionBroadcastReceiver = null;
            }
            if ((!isProvApn) || mIsProvisioning) {
                // Hide any provisioning notification.
                cm.setProvisioningNotificationVisible(false, ConnectivityManager.TYPE_MOBILE, INTENT_PROVISION + ":" + mPhone.getPhoneId());
                // Complete the connection normally notifying the world we're connected.
                // We do this if this isn't a special provisioning apn or if we've been
                // told its time to provision.
                completeConnection(apnContext, requestType);
            } else {
                // is sent to the DCT.
                if (DBG) {
                    log("onDataSetupComplete: successful, BUT send connected to prov apn as" + " mIsProvisioning:" + mIsProvisioning + " == false" + " && (isProvisioningApn:" + isProvApn + " == true");
                }
                // While radio is up, grab provisioning URL.  The URL contains ICCID which
                // disappears when radio is off.
                mProvisionBroadcastReceiver = new ProvisionNotificationBroadcastReceiver(cm.getMobileProvisioningUrl(), mTelephonyManager.getNetworkOperatorName());
                mPhone.getContext().registerReceiver(mProvisionBroadcastReceiver, new IntentFilter(INTENT_PROVISION));
                // Put up user notification that sign-in is required.
                cm.setProvisioningNotificationVisible(true, ConnectivityManager.TYPE_MOBILE, INTENT_PROVISION + ":" + mPhone.getPhoneId());
                // Turn off radio to save battery and avoid wasting carrier resources.
                // The network isn't usable and network validation will just fail anyhow.
                setRadio(false);
            }
            if (DBG) {
                log("onDataSetupComplete: SETUP complete type=" + apnContext.getApnType());
            }
            if (TelephonyUtils.IS_DEBUGGABLE) {
                // adb shell setprop persist.radio.test.pco [pco_val]
                String radioTestProperty = "persist.radio.test.pco";
                int pcoVal = SystemProperties.getInt(radioTestProperty, -1);
                if (pcoVal != -1) {
                    log("PCO testing: read pco value from persist.radio.test.pco " + pcoVal);
                    final byte[] value = new byte[1];
                    value[0] = (byte) pcoVal;
                    final Intent intent = new Intent(TelephonyManager.ACTION_CARRIER_SIGNAL_PCO_VALUE);
                    intent.putExtra(TelephonyManager.EXTRA_APN_TYPE, "default");
                    intent.putExtra(TelephonyManager.EXTRA_APN_TYPE_INT, TYPE_DEFAULT);
                    intent.putExtra(TelephonyManager.EXTRA_APN_PROTOCOL, "IPV4V6");
                    intent.putExtra(TelephonyManager.EXTRA_APN_PROTOCOL_INT, PROTOCOL_IPV4V6);
                    intent.putExtra(TelephonyManager.EXTRA_PCO_ID, 0xFF00);
                    intent.putExtra(TelephonyManager.EXTRA_PCO_VALUE, value);
                    mPhone.getCarrierSignalAgent().notifyCarrierSignalReceivers(intent);
                }
            }
        }
    } else {
        if (DBG) {
            ApnSetting apn = apnContext.getApnSetting();
            log("onDataSetupComplete: error apn=" + apn.getApnName() + ", cause=" + cause + ", requestType=" + requestTypeToString(requestType));
        }
        if (DataFailCause.isEventLoggable(cause)) {
            // Log this failure to the Event Logs.
            int cid = getCellLocationId();
            EventLog.writeEvent(EventLogTags.PDP_SETUP_FAIL, cause, cid, mTelephonyManager.getNetworkType());
        }
        ApnSetting apn = apnContext.getApnSetting();
        mPhone.notifyDataConnectionFailed(apnContext.getApnType(), apn != null ? apn.getApnName() : null, cause);
        // Compose broadcast intent send to the specific carrier signaling receivers
        Intent intent = new Intent(TelephonyManager.ACTION_CARRIER_SIGNAL_REQUEST_NETWORK_FAILED);
        intent.putExtra(TelephonyManager.EXTRA_ERROR_CODE, cause);
        intent.putExtra(TelephonyManager.EXTRA_APN_TYPE, apnContext.getApnType());
        intent.putExtra(TelephonyManager.EXTRA_APN_TYPE_INT, ApnSetting.getApnTypesBitmaskFromString(apnContext.getApnType()));
        mPhone.getCarrierSignalAgent().notifyCarrierSignalReceivers(intent);
        if (DataFailCause.isRadioRestartFailure(mPhone.getContext(), cause, mPhone.getSubId()) || apnContext.restartOnError(cause)) {
            if (DBG)
                log("Modem restarted.");
            sendRestartRadio();
        }
        // failed.
        if (isPermanentFailure(cause)) {
            log("cause = " + cause + ", mark apn as permanent failed. apn = " + apn);
            apnContext.markApnPermanentFailed(apn);
        }
        onDataSetupCompleteError(apnContext, requestType);
    }
}
Also used : IntentFilter(android.content.IntentFilter) Message(android.os.Message) ConnectivityManager(android.net.ConnectivityManager) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) ContentResolver(android.content.ContentResolver) ProxyInfo(android.net.ProxyInfo) ApnSetting(android.telephony.data.ApnSetting)

Example 35 with ApnSetting

use of android.telephony.data.ApnSetting 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)

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