Loading src/java/com/android/internal/telephony/dataconnection/ApnSetting.java +51 −19 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ import android.telephony.Rlog; import android.telephony.ServiceState; import android.text.TextUtils; import com.android.internal.telephony.Phone; import com.android.internal.telephony.PhoneConstants; import com.android.internal.telephony.RILConstants; import com.android.internal.telephony.uicc.IccRecords; Loading Loading @@ -404,15 +405,41 @@ public class ApnSetting { 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) ? CarrierConfigManager.KEY_CARRIER_METERED_ROAMING_APN_TYPES_STRINGS : CarrierConfigManager.KEY_CARRIER_METERED_APN_TYPES_STRINGS; 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) context.getSystemService(Context.CARRIER_CONFIG_SERVICE); phone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE); if (configManager == null) { Rlog.e(LOG_TAG, "Carrier config service is not available"); return true; Loading @@ -432,44 +459,49 @@ public class ApnSetting { 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()) + " isRoaming: " + isRoaming); 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. isRoaming: " + isRoaming); 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. isRoaming: " + isRoaming); 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. isRoaming: " + isRoaming); if (DBG) Rlog.d(LOG_TAG, "APN_TYPE_ALL APN is metered."); 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; } 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) { // If one of the APN type is metered, then this APN setting is metered. if (isMeteredApnType(type, context, subId, isRoaming)) { if (DBG) Rlog.d(LOG_TAG, "Metered. APN = " + toString() + "isRoaming: " + isRoaming); if (isMeteredApnType(type, phone)) { return true; } } if (DBG) Rlog.d(LOG_TAG, "Not metered. APN = " + toString() + "isRoaming: " + isRoaming); return false; } Loading src/java/com/android/internal/telephony/dataconnection/DataConnection.java +3 −7 Original line number Diff line number Diff line Loading @@ -852,8 +852,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.getContext(), mPhone.getSubId(), mPhone.getServiceState().getDataRoaming())) { if (!mApnSetting.isMetered(mPhone)) { return; } Loading @@ -869,9 +868,7 @@ public class DataConnection extends StateMachine { for (String type : mApnSetting.types) { if (!mRestrictedNetworkOverride && (mConnectionParams != null && mConnectionParams.mUnmeteredUseOnly) && ApnSetting.isMeteredApnType(type, mPhone.getContext(), mPhone.getSubId(), mPhone.getServiceState().getDataRoaming())) { && ApnSetting.isMeteredApnType(type, mPhone)) { log("Dropped the metered " + type + " for the unmetered data call."); continue; } Loading Loading @@ -934,8 +931,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.getContext(), mPhone.getSubId(), mPhone.getServiceState().getDataRoaming())) { || !mApnSetting.isMetered(mPhone)) { result.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED); mNetworkInfo.setMetered(false); } else { Loading src/java/com/android/internal/telephony/dataconnection/DcTracker.java +3 −6 Original line number Diff line number Diff line Loading @@ -904,8 +904,7 @@ public class DcTracker extends Handler { // data connection. apnContext.setReason(Phone.REASON_DATA_ENABLED); cleanUpConnection(true, apnContext); } else if (apnContext.getApnSetting().isMetered(mPhone.getContext(), mPhone.getSubId(), mPhone.getServiceState().getDataRoaming()) } else if (apnContext.getApnSetting().isMetered(mPhone) && (netCaps != null && netCaps.hasCapability( NetworkCapabilities.NET_CAPABILITY_NOT_METERED))) { if (DBG) { Loading Loading @@ -1319,8 +1318,7 @@ public class DcTracker extends Handler { SubscriptionManager.getDefaultDataSubscriptionId()); boolean isMeteredApnType = apnContext == null || ApnSetting.isMeteredApnType(apnContext.getApnType(), mPhone.getContext(), mPhone.getSubId(), mPhone.getServiceState().getDataRoaming()); || ApnSetting.isMeteredApnType(apnContext.getApnType(), mPhone); PhoneConstants.State phoneState = PhoneConstants.State.IDLE; // Note this is explicitly not using mPhone.getState. See b/19090488. Loading Loading @@ -1646,8 +1644,7 @@ public class DcTracker extends Handler { // Use ApnSetting to decide metered or non-metered. // Tear down all metered data connections. ApnSetting apnSetting = apnContext.getApnSetting(); if (apnSetting != null && apnSetting.isMetered(mPhone.getContext(), mPhone.getSubId(), mPhone.getServiceState().getDataRoaming())) { if (apnSetting != null && apnSetting.isMetered(mPhone)) { if (DBG) log("clean up metered ApnContext Type: " + apnContext.getApnType()); apnContext.setReason(reason); cleanUpConnection(tearDown, apnContext); Loading Loading
src/java/com/android/internal/telephony/dataconnection/ApnSetting.java +51 −19 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ import android.telephony.Rlog; import android.telephony.ServiceState; import android.text.TextUtils; import com.android.internal.telephony.Phone; import com.android.internal.telephony.PhoneConstants; import com.android.internal.telephony.RILConstants; import com.android.internal.telephony.uicc.IccRecords; Loading Loading @@ -404,15 +405,41 @@ public class ApnSetting { 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) ? CarrierConfigManager.KEY_CARRIER_METERED_ROAMING_APN_TYPES_STRINGS : CarrierConfigManager.KEY_CARRIER_METERED_APN_TYPES_STRINGS; 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) context.getSystemService(Context.CARRIER_CONFIG_SERVICE); phone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE); if (configManager == null) { Rlog.e(LOG_TAG, "Carrier config service is not available"); return true; Loading @@ -432,44 +459,49 @@ public class ApnSetting { 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()) + " isRoaming: " + isRoaming); 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. isRoaming: " + isRoaming); 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. isRoaming: " + isRoaming); 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. isRoaming: " + isRoaming); if (DBG) Rlog.d(LOG_TAG, "APN_TYPE_ALL APN is metered."); 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; } 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) { // If one of the APN type is metered, then this APN setting is metered. if (isMeteredApnType(type, context, subId, isRoaming)) { if (DBG) Rlog.d(LOG_TAG, "Metered. APN = " + toString() + "isRoaming: " + isRoaming); if (isMeteredApnType(type, phone)) { return true; } } if (DBG) Rlog.d(LOG_TAG, "Not metered. APN = " + toString() + "isRoaming: " + isRoaming); return false; } Loading
src/java/com/android/internal/telephony/dataconnection/DataConnection.java +3 −7 Original line number Diff line number Diff line Loading @@ -852,8 +852,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.getContext(), mPhone.getSubId(), mPhone.getServiceState().getDataRoaming())) { if (!mApnSetting.isMetered(mPhone)) { return; } Loading @@ -869,9 +868,7 @@ public class DataConnection extends StateMachine { for (String type : mApnSetting.types) { if (!mRestrictedNetworkOverride && (mConnectionParams != null && mConnectionParams.mUnmeteredUseOnly) && ApnSetting.isMeteredApnType(type, mPhone.getContext(), mPhone.getSubId(), mPhone.getServiceState().getDataRoaming())) { && ApnSetting.isMeteredApnType(type, mPhone)) { log("Dropped the metered " + type + " for the unmetered data call."); continue; } Loading Loading @@ -934,8 +931,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.getContext(), mPhone.getSubId(), mPhone.getServiceState().getDataRoaming())) { || !mApnSetting.isMetered(mPhone)) { result.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED); mNetworkInfo.setMetered(false); } else { Loading
src/java/com/android/internal/telephony/dataconnection/DcTracker.java +3 −6 Original line number Diff line number Diff line Loading @@ -904,8 +904,7 @@ public class DcTracker extends Handler { // data connection. apnContext.setReason(Phone.REASON_DATA_ENABLED); cleanUpConnection(true, apnContext); } else if (apnContext.getApnSetting().isMetered(mPhone.getContext(), mPhone.getSubId(), mPhone.getServiceState().getDataRoaming()) } else if (apnContext.getApnSetting().isMetered(mPhone) && (netCaps != null && netCaps.hasCapability( NetworkCapabilities.NET_CAPABILITY_NOT_METERED))) { if (DBG) { Loading Loading @@ -1319,8 +1318,7 @@ public class DcTracker extends Handler { SubscriptionManager.getDefaultDataSubscriptionId()); boolean isMeteredApnType = apnContext == null || ApnSetting.isMeteredApnType(apnContext.getApnType(), mPhone.getContext(), mPhone.getSubId(), mPhone.getServiceState().getDataRoaming()); || ApnSetting.isMeteredApnType(apnContext.getApnType(), mPhone); PhoneConstants.State phoneState = PhoneConstants.State.IDLE; // Note this is explicitly not using mPhone.getState. See b/19090488. Loading Loading @@ -1646,8 +1644,7 @@ public class DcTracker extends Handler { // Use ApnSetting to decide metered or non-metered. // Tear down all metered data connections. ApnSetting apnSetting = apnContext.getApnSetting(); if (apnSetting != null && apnSetting.isMetered(mPhone.getContext(), mPhone.getSubId(), mPhone.getServiceState().getDataRoaming())) { if (apnSetting != null && apnSetting.isMetered(mPhone)) { if (DBG) log("clean up metered ApnContext Type: " + apnContext.getApnType()); apnContext.setReason(reason); cleanUpConnection(tearDown, apnContext); Loading