Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 80925a70 authored by yuemingw's avatar yuemingw
Browse files

Remove internal ApnSetting.

Bug: 77511388
Test: atest FrameworksTelephonyTests
Change-Id: Ib833aeb098ec1b0f3779351c370c02abda178ede
Merged-In: Idb4aff2879577c109c0d81671e1398e7bca14d0e
parent 8f1097bf
Loading
Loading
Loading
Loading
+9 −6
Original line number Diff line number Diff line
@@ -22,11 +22,10 @@ import android.os.PersistableBundle;
import android.os.SystemProperties;
import android.telephony.CarrierConfigManager;
import android.telephony.Rlog;
import android.telephony.data.ApnSetting;
import android.text.TextUtils;
import android.util.Pair;

import com.android.internal.telephony.dataconnection.ApnSetting;

import java.util.ArrayList;
import java.util.Random;

@@ -506,7 +505,9 @@ public class RetryManager {
            if (++index == mWaitingApns.size()) index = 0;

            // Stop if we find the non-failed APN.
            if (mWaitingApns.get(index).permanentFailed == false) break;
            if (!mWaitingApns.get(index).getPermanentFailed()) {
                break;
            }

            // If we've already cycled through all the APNs, that means there is no APN we can try
            if (index == mCurrentApnIndex) return null;
@@ -553,7 +554,9 @@ public class RetryManager {
            if (++index >= mWaitingApns.size()) index = 0;

            // Stop if we find the non-failed APN.
            if (mWaitingApns.get(index).permanentFailed == false) break;
            if (!mWaitingApns.get(index).getPermanentFailed()) {
                break;
            }

            // If we've already cycled through all the APNs, that means all APNs have
            // permanently failed
@@ -594,7 +597,7 @@ public class RetryManager {
     * */
    public void markApnPermanentFailed(ApnSetting apn) {
        if (apn != null) {
            apn.permanentFailed = true;
            apn.setPermanentFailed(true);
        }
    }

@@ -627,7 +630,7 @@ public class RetryManager {
        configureRetry();

        for (ApnSetting apn : mWaitingApns) {
            apn.permanentFailed = false;
            apn.setPermanentFailed(false);
        }

        log("Setting " + mWaitingApns.size() + " waiting APNs.");
+11 −2
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.net.NetworkCapabilities;
import android.net.NetworkConfig;
import android.net.NetworkRequest;
import android.telephony.Rlog;
import android.telephony.data.ApnSetting;
import android.text.TextUtils;
import android.util.LocalLog;
import android.util.SparseIntArray;
@@ -128,6 +129,14 @@ public class ApnContext {
        return mApnType;
    }

    /**
     * Gets the APN type bitmask.
     * @return The APN type bitmask
     */
    public int getApnTypeBitmask() {
        return ApnSetting.getApnTypesBitmaskFromString(mApnType);
    }

    /**
     * Get the data call async channel.
     * @return The data call async channel
@@ -392,8 +401,8 @@ public class ApnContext {
        String provisioningApn = mPhone.getContext().getResources()
                .getString(R.string.mobile_provisioning_apn);
        if (!TextUtils.isEmpty(provisioningApn) &&
                (mApnSetting != null) && (mApnSetting.apn != null)) {
            return (mApnSetting.apn.equals(provisioningApn));
                (mApnSetting != null) && (mApnSetting.getApnName() != null)) {
            return (mApnSetting.getApnName().equals(provisioningApn));
        } else {
            return false;
        }
+0 −832

File deleted.

Preview size limit exceeded, changes collapsed.

+215 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.internal.telephony.dataconnection;

import android.content.Context;
import android.os.PersistableBundle;
import android.telephony.CarrierConfigManager;
import android.telephony.Rlog;
import android.telephony.ServiceState;
import android.telephony.data.ApnSetting;
import android.util.Log;

import com.android.internal.telephony.Phone;
import com.android.internal.telephony.PhoneConstants;
import com.android.internal.telephony.uicc.IccRecords;

import java.util.Arrays;
import java.util.HashSet;

/**
 * This class represents a apn setting for create PDP link
 */
public class ApnSettingUtils {

    static final String LOG_TAG = "ApnSetting";

    private static final boolean DBG = false;

    private static boolean iccidMatches(String mvnoData, String iccId) {
        String[] mvnoIccidList = mvnoData.split(",");
        for (String mvnoIccid : mvnoIccidList) {
            if (iccId.startsWith(mvnoIccid)) {
                Log.d(LOG_TAG, "mvno icc id match found");
                return true;
            }
        }
        return false;
    }

    private static boolean imsiMatches(String imsiDB, String imsiSIM) {
        // Note: imsiDB value has digit number or 'x' character for seperating USIM information
        // for MVNO operator. And then digit number is matched at same order and 'x' character
        // could replace by any digit number.
        // ex) if imsiDB inserted '310260x10xxxxxx' for GG Operator,
        //     that means first 6 digits, 8th and 9th digit
        //     should be set in USIM for GG Operator.
        int len = imsiDB.length();

        if (len <= 0) return false;
        if (len > imsiSIM.length()) return false;

        for (int idx = 0; idx < len; idx++) {
            char c = imsiDB.charAt(idx);
            if ((c == 'x') || (c == 'X') || (c == imsiSIM.charAt(idx))) {
                continue;
            } else {
                return false;
            }
        }
        return true;
    }

    /**
     * Check if MVNO type and data match IccRecords.
     *
     * @param r the IccRecords
     * @param mvnoType the MVNO type
     * @param mvnoMatchData the MVNO match data
     * @return {@code true} if MVNO type and data match IccRecords, {@code false} otherwise.
     */
    public static boolean mvnoMatches(IccRecords r, int mvnoType, String mvnoMatchData) {
        if (mvnoType == ApnSetting.MVNO_TYPE_SPN) {
            if ((r.getServiceProviderName() != null)
                    && r.getServiceProviderName().equalsIgnoreCase(mvnoMatchData)) {
                return true;
            }
        } else if (mvnoType == ApnSetting.MVNO_TYPE_IMSI) {
            String imsiSIM = r.getIMSI();
            if ((imsiSIM != null) && imsiMatches(mvnoMatchData, imsiSIM)) {
                return true;
            }
        } else if (mvnoType == ApnSetting.MVNO_TYPE_GID) {
            String gid1 = r.getGid1();
            int mvno_match_data_length = mvnoMatchData.length();
            if ((gid1 != null) && (gid1.length() >= mvno_match_data_length)
                    && gid1.substring(0, mvno_match_data_length).equalsIgnoreCase(mvnoMatchData)) {
                return true;
            }
        } else if (mvnoType == ApnSetting.MVNO_TYPE_ICCID) {
            String iccId = r.getIccId();
            if ((iccId != null) && iccidMatches(mvnoMatchData, iccId)) {
                return true;
            }
        }

        return false;
    }

    /**
     * Check if this APN type is metered.
     *
     * @param type the APN type
     * @param phone the phone object
     * @return {@code true} if the APN type is metered, {@code false} otherwise.
     */
    public static boolean isMeteredApnType(String type, Phone phone) {
        if (phone == null) {
            return true;
        }

        boolean isRoaming = phone.getServiceState().getDataRoaming();
        boolean isIwlan = phone.getServiceState().getRilDataRadioTechnology()
                == ServiceState.RIL_RADIO_TECHNOLOGY_IWLAN;
        int subId = phone.getSubId();

        String carrierConfig;
        // First check if the device is in IWLAN mode. If yes, use the IWLAN metered APN list. Then
        // check if the device is roaming. If yes, use the roaming metered APN list. Otherwise, use
        // the normal metered APN list.
        if (isIwlan) {
            carrierConfig = CarrierConfigManager.KEY_CARRIER_METERED_IWLAN_APN_TYPES_STRINGS;
        } else if (isRoaming) {
            carrierConfig = CarrierConfigManager.KEY_CARRIER_METERED_ROAMING_APN_TYPES_STRINGS;
        } else {
            carrierConfig = CarrierConfigManager.KEY_CARRIER_METERED_APN_TYPES_STRINGS;
        }

        if (DBG) {
            Rlog.d(LOG_TAG, "isMeteredApnType: isRoaming=" + isRoaming + ", isIwlan=" + isIwlan);
        }

        CarrierConfigManager configManager = (CarrierConfigManager)
                phone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
        if (configManager == null) {
            Rlog.e(LOG_TAG, "Carrier config service is not available");
            return true;
        }

        PersistableBundle b = configManager.getConfigForSubId(subId);
        if (b == null) {
            Rlog.e(LOG_TAG, "Can't get the config. subId = " + subId);
            return true;
        }

        String[] meteredApnTypes = b.getStringArray(carrierConfig);
        if (meteredApnTypes == null) {
            Rlog.e(LOG_TAG, carrierConfig +  " is not available. " + "subId = " + subId);
            return true;
        }

        HashSet<String> meteredApnSet = new HashSet<>(Arrays.asList(meteredApnTypes));
        if (DBG) {
            Rlog.d(LOG_TAG, "For subId = " + subId + ", metered APN types are "
                    + Arrays.toString(meteredApnSet.toArray()));
        }

        // If all types of APN are metered, then this APN setting must be metered.
        if (meteredApnSet.contains(PhoneConstants.APN_TYPE_ALL)) {
            if (DBG) Rlog.d(LOG_TAG, "All APN types are metered.");
            return true;
        }

        if (meteredApnSet.contains(type)) {
            if (DBG) Rlog.d(LOG_TAG, type + " is metered.");
            return true;
        } else if (type.equals(PhoneConstants.APN_TYPE_ALL)) {
            // Assuming no configuration error, if at least one APN type is
            // metered, then this APN setting is metered.
            if (meteredApnSet.size() > 0) {
                if (DBG) Rlog.d(LOG_TAG, "APN_TYPE_ALL APN is metered.");
                return true;
            }
        }

        if (DBG) Rlog.d(LOG_TAG, type + " is not metered.");
        return false;
    }

    /**
     * Check if this APN setting is metered.
     *
     * @param phone The phone object
     * @return True if this APN setting is metered, otherwise false.
     */
    public static boolean isMetered(ApnSetting apn, Phone phone) {
        if (phone == null) {
            return true;
        }

        String[] types = ApnSetting.getApnTypesStringFromBitmask(
                apn.getApnTypeBitmask()).split(",");

        for (String type : types) {
            // If one of the APN type is metered, then this APN setting is metered.
            if (isMeteredApnType(type, phone)) {
                return true;
            }
        }
        return false;
    }
}
+23 −17
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import android.telephony.AccessNetworkConstants;
import android.telephony.Rlog;
import android.telephony.ServiceState;
import android.telephony.TelephonyManager;
import android.telephony.data.ApnSetting;
import android.telephony.data.DataCallResponse;
import android.telephony.data.DataProfile;
import android.telephony.data.DataService;
@@ -443,9 +444,9 @@ public class DataConnection extends StateMachine {
            return;
        }

        if (apn != null && apn.mtu != PhoneConstants.UNSET_MTU) {
            lp.setMtu(apn.mtu);
            if (DBG) log("MTU set by APN to: " + apn.mtu);
        if (apn != null && apn.getMtu() != PhoneConstants.UNSET_MTU) {
            lp.setMtu(apn.getMtu());
            if (DBG) log("MTU set by APN to: " + apn.getMtu());
            return;
        }

@@ -502,9 +503,12 @@ public class DataConnection extends StateMachine {
     * @param cp is the connection parameters
     */
    private void onConnect(ConnectionParams cp) {
        if (DBG) log("onConnect: carrier='" + mApnSetting.carrier
                + "' APN='" + mApnSetting.apn
                + "' proxy='" + mApnSetting.proxy + "' port='" + mApnSetting.port + "'");
        if (DBG) {
            log("onConnect: carrier='" + mApnSetting.getEntryName()
                    + "' APN='" + mApnSetting.getApnName()
                    + "' proxy='" + mApnSetting.getProxyAddressAsString()
                    + "' port='" + mApnSetting.getProxyPort() + "'");
        }
        if (cp.mApnContext != null) cp.mApnContext.requestLog("DataConnection.onConnect");

        // Check if we should fake an error.
@@ -783,12 +787,12 @@ public class DataConnection extends StateMachine {
            // Do not apply the race condition workaround for MMS APN
            // if Proxy is an IP-address.
            // Otherwise, the default APN will not be restored anymore.
            if (!mApnSetting.types[0].equals(PhoneConstants.APN_TYPE_MMS)
                || !isIpAddress(mApnSetting.mmsProxy)) {
            if (!isIpAddress(mApnSetting.getMmsProxyAddressAsString())) {
                log(String.format(
                        "isDnsOk: return false apn.types[0]=%s APN_TYPE_MMS=%s isIpAddress(%s)=%s",
                        mApnSetting.types[0], PhoneConstants.APN_TYPE_MMS, mApnSetting.mmsProxy,
                        isIpAddress(mApnSetting.mmsProxy)));
                        "isDnsOk: return false apn.types=%d APN_TYPE_MMS=%s isIpAddress(%s)=%s",
                        mApnSetting.getApnTypeBitmask(), PhoneConstants.APN_TYPE_MMS,
                        mApnSetting.getMmsProxyAddressAsString(),
                        isIpAddress(mApnSetting.getMmsProxyAddressAsString())));
                return false;
            }
        }
@@ -922,7 +926,7 @@ public class DataConnection extends StateMachine {

        // Do we need a restricted network to satisfy the request?
        // Is this network metered?  If not, then don't add restricted
        if (!mApnSetting.isMetered(mPhone)) {
        if (!ApnSettingUtils.isMetered(mApnSetting, mPhone)) {
            return;
        }

@@ -935,10 +939,12 @@ public class DataConnection extends StateMachine {
        result.addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR);

        if (mApnSetting != null) {
            for (String type : mApnSetting.types) {
            final String[] types = ApnSetting.getApnTypesStringFromBitmask(
                mApnSetting.getApnTypeBitmask()).split(",");
            for (String type : types) {
                if (!mRestrictedNetworkOverride
                        && (mConnectionParams != null && mConnectionParams.mUnmeteredUseOnly)
                        && ApnSetting.isMeteredApnType(type, mPhone)) {
                        && ApnSettingUtils.isMeteredApnType(type, mPhone)) {
                    log("Dropped the metered " + type + " for the unmetered data call.");
                    continue;
                }
@@ -999,7 +1005,7 @@ public class DataConnection extends StateMachine {
            // 2. The non-restricted data and is intended for unmetered use only.
            if (((mConnectionParams != null && mConnectionParams.mUnmeteredUseOnly)
                    && !mRestrictedNetworkOverride)
                    || !mApnSetting.isMetered(mPhone)) {
                    || !ApnSettingUtils.isMetered(mApnSetting, mPhone)) {
                result.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED);
            } else {
                result.removeCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED);
@@ -1170,7 +1176,7 @@ public class DataConnection extends StateMachine {
            // only NOT be set only if we're in DcInactiveState.
            mApnSetting = apnContext.getApnSetting();
        }
        if (mApnSetting == null || !mApnSetting.canHandleType(apnContext.getApnType())) {
        if (mApnSetting == null || !mApnSetting.canHandleType(apnContext.getApnTypeBitmask())) {
            if (DBG) {
                log("initConnection: incompatible apnSetting in ConnectionParams cp=" + cp
                        + " dc=" + DataConnection.this);
@@ -1683,7 +1689,7 @@ public class DataConnection extends StateMachine {

            mNetworkInfo.setDetailedState(NetworkInfo.DetailedState.CONNECTED,
                    mNetworkInfo.getReason(), null);
            mNetworkInfo.setExtraInfo(mApnSetting.apn);
            mNetworkInfo.setExtraInfo(mApnSetting.getApnName());
            updateTcpBufferSizes(mRilRat);

            final NetworkMisc misc = new NetworkMisc();
Loading