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

Commit 3e25fa7e authored by Jack Yu's avatar Jack Yu Committed by android-build-merger
Browse files

Merge changes from topic 'iwlan_unit'

am: 21def163

Change-Id: Ie22d47da87eddc884556a34105ca661018844c74
parents 23035812 21def163
Loading
Loading
Loading
Loading
+51 −19
Original line number Original line Diff line number Diff line
@@ -24,6 +24,7 @@ import android.telephony.Rlog;
import android.telephony.ServiceState;
import android.telephony.ServiceState;
import android.text.TextUtils;
import android.text.TextUtils;


import com.android.internal.telephony.Phone;
import com.android.internal.telephony.PhoneConstants;
import com.android.internal.telephony.PhoneConstants;
import com.android.internal.telephony.RILConstants;
import com.android.internal.telephony.RILConstants;
import com.android.internal.telephony.uicc.IccRecords;
import com.android.internal.telephony.uicc.IccRecords;
@@ -404,15 +405,41 @@ public class ApnSetting {
        return false;
        return false;
    }
    }


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


        String carrierConfig = (isRoaming) ?
        boolean isRoaming = phone.getServiceState().getDataRoaming();
                CarrierConfigManager.KEY_CARRIER_METERED_ROAMING_APN_TYPES_STRINGS :
        boolean isIwlan = phone.getServiceState().getRilDataRadioTechnology()
                CarrierConfigManager.KEY_CARRIER_METERED_APN_TYPES_STRINGS;
                == 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)
        CarrierConfigManager configManager = (CarrierConfigManager)
                context.getSystemService(Context.CARRIER_CONFIG_SERVICE);
                phone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
        if (configManager == null) {
        if (configManager == null) {
            Rlog.e(LOG_TAG, "Carrier config service is not available");
            Rlog.e(LOG_TAG, "Carrier config service is not available");
            return true;
            return true;
@@ -432,44 +459,49 @@ public class ApnSetting {


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


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


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


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


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

        for (String type : types) {
        for (String type : types) {
            // If one of the APN type is metered, then this APN setting is metered.
            // If one of the APN type is metered, then this APN setting is metered.
            if (isMeteredApnType(type, context, subId, isRoaming)) {
            if (isMeteredApnType(type, phone)) {
                if (DBG) Rlog.d(LOG_TAG, "Metered. APN = " + toString() +
                        "isRoaming: " + isRoaming);
                return true;
                return true;
            }
            }
        }
        }
        if (DBG) Rlog.d(LOG_TAG, "Not metered. APN = " + toString() + "isRoaming: " + isRoaming);
        return false;
        return false;
    }
    }


+3 −7
Original line number Original line Diff line number Diff line
@@ -852,8 +852,7 @@ public class DataConnection extends StateMachine {


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


@@ -869,9 +868,7 @@ public class DataConnection extends StateMachine {
            for (String type : mApnSetting.types) {
            for (String type : mApnSetting.types) {
                if (!mRestrictedNetworkOverride
                if (!mRestrictedNetworkOverride
                        && (mConnectionParams != null && mConnectionParams.mUnmeteredUseOnly)
                        && (mConnectionParams != null && mConnectionParams.mUnmeteredUseOnly)
                        && ApnSetting.isMeteredApnType(type,
                        && ApnSetting.isMeteredApnType(type, mPhone)) {
                        mPhone.getContext(), mPhone.getSubId(),
                        mPhone.getServiceState().getDataRoaming())) {
                    log("Dropped the metered " + type + " for the unmetered data call.");
                    log("Dropped the metered " + type + " for the unmetered data call.");
                    continue;
                    continue;
                }
                }
@@ -934,8 +931,7 @@ public class DataConnection extends StateMachine {
            // 2. The non-restricted data and is intended for unmetered use only.
            // 2. The non-restricted data and is intended for unmetered use only.
            if (((mConnectionParams != null && mConnectionParams.mUnmeteredUseOnly)
            if (((mConnectionParams != null && mConnectionParams.mUnmeteredUseOnly)
                    && !mRestrictedNetworkOverride)
                    && !mRestrictedNetworkOverride)
                    || !mApnSetting.isMetered(mPhone.getContext(), mPhone.getSubId(),
                    || !mApnSetting.isMetered(mPhone)) {
                    mPhone.getServiceState().getDataRoaming())) {
                result.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED);
                result.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED);
                mNetworkInfo.setMetered(false);
                mNetworkInfo.setMetered(false);
            } else {
            } else {
+3 −6
Original line number Original line Diff line number Diff line
@@ -904,8 +904,7 @@ public class DcTracker extends Handler {
                            // data connection.
                            // data connection.
                            apnContext.setReason(Phone.REASON_DATA_ENABLED);
                            apnContext.setReason(Phone.REASON_DATA_ENABLED);
                            cleanUpConnection(true, apnContext);
                            cleanUpConnection(true, apnContext);
                        } else if (apnContext.getApnSetting().isMetered(mPhone.getContext(),
                        } else if (apnContext.getApnSetting().isMetered(mPhone)
                                mPhone.getSubId(), mPhone.getServiceState().getDataRoaming())
                                && (netCaps != null && netCaps.hasCapability(
                                && (netCaps != null && netCaps.hasCapability(
                                        NetworkCapabilities.NET_CAPABILITY_NOT_METERED))) {
                                        NetworkCapabilities.NET_CAPABILITY_NOT_METERED))) {
                            if (DBG) {
                            if (DBG) {
@@ -1319,8 +1318,7 @@ public class DcTracker extends Handler {
                SubscriptionManager.getDefaultDataSubscriptionId());
                SubscriptionManager.getDefaultDataSubscriptionId());


        boolean isMeteredApnType = apnContext == null
        boolean isMeteredApnType = apnContext == null
                || ApnSetting.isMeteredApnType(apnContext.getApnType(), mPhone.getContext(),
                || ApnSetting.isMeteredApnType(apnContext.getApnType(), mPhone);
                        mPhone.getSubId(), mPhone.getServiceState().getDataRoaming());


        PhoneConstants.State phoneState = PhoneConstants.State.IDLE;
        PhoneConstants.State phoneState = PhoneConstants.State.IDLE;
        // Note this is explicitly not using mPhone.getState.  See b/19090488.
        // Note this is explicitly not using mPhone.getState.  See b/19090488.
@@ -1646,8 +1644,7 @@ public class DcTracker extends Handler {
                // Use ApnSetting to decide metered or non-metered.
                // Use ApnSetting to decide metered or non-metered.
                // Tear down all metered data connections.
                // Tear down all metered data connections.
                ApnSetting apnSetting = apnContext.getApnSetting();
                ApnSetting apnSetting = apnContext.getApnSetting();
                if (apnSetting != null && apnSetting.isMetered(mPhone.getContext(),
                if (apnSetting != null && apnSetting.isMetered(mPhone)) {
                        mPhone.getSubId(), mPhone.getServiceState().getDataRoaming())) {
                    if (DBG) log("clean up metered ApnContext Type: " + apnContext.getApnType());
                    if (DBG) log("clean up metered ApnContext Type: " + apnContext.getApnType());
                    apnContext.setReason(reason);
                    apnContext.setReason(reason);
                    cleanUpConnection(tearDown, apnContext);
                    cleanUpConnection(tearDown, apnContext);