我们经常在Log中看到,有的LTE =13,而有的LTE =14,其实不然,这两个都表示LTE 4G网络,下面我们来看一下这中间的原因。
在TelephonyManager.java中:
/** Current network is LTE */
public static final int NETWORK_TYPE_LTE = 13;
/** Current network is eHRPD */
public static final int NETWORK_TYPE_EHRPD = 14;
这里定义的NETWORK_TYPE_LTE=13;
而在ServiceState.java中:
/** @hide */
public static final int RIL_RADIO_TECHNOLOGY_EHRPD = 13;
/** @hide */
public static final int RIL_RADIO_TECHNOLOGY_LTE = 14;
这里定义的RIL_RADIO_TECHNOLOGY_LTE = 14;
问题来了,那么我们要按照哪个标准来解决Log呢?来分析一下转换过程。
在ServiceState.java里有个函数rilRadioTechnologyToNetworkType(),用来转换RadioTechnology与NetworkType。
private int rilRadioTechnologyToNetworkType(int rt) {
switch(rt) {
case ServiceState.RIL_RADIO_TECHNOLOGY_GPRS:
return TelephonyManager.NETWORK_TYPE_GPRS;
case ServiceState.RIL_RADIO_TECHNOLOGY_EDGE:
return TelephonyManager.NETWORK_TYPE_EDGE;
case ServiceState.RIL_RADIO_TECHNOLOGY_UMTS:
return TelephonyManager.NETWORK_TYPE_UMTS;
case ServiceState.RIL_RADIO_TECHNOLOGY_HSDPA:
return TelephonyManager.NETWORK_TYPE_HSDPA;
case ServiceState.RIL_RADIO_TECHNOLOGY_HSUPA:
return TelephonyManager.NETWORK_TYPE_HSUPA;
case ServiceState.RIL_RADIO_TECHNOLOGY_HSPA:
return TelephonyManager.NETWORK_TYPE_HSPA;
case ServiceState.RIL_RADIO_TECHNOLOGY_IS95A:
case ServiceState.RIL_RADIO_TECHNOLOGY_IS95B:
return TelephonyManager.NETWORK_TYPE_CDMA;
case ServiceState.RIL_RADIO_TECHNOLOGY_1xRTT:
return TelephonyManager.NETWORK_TYPE_1xRTT;
case ServiceState.RIL_RADIO_TECHNOLOGY_EVDO_0:
return TelephonyManager.NETWORK_TYPE_EVDO_0;
case ServiceState.RIL_RADIO_TECHNOLOGY_EVDO_A:
return TelephonyManager.NETWORK_TYPE_EVDO_A;
case ServiceState.RIL_RADIO_TECHNOLOGY_EVDO_B:
return TelephonyManager.NETWORK_TYPE_EVDO_B;
case ServiceState.RIL_RADIO_TECHNOLOGY_EHRPD:
return TelephonyManager.NETWORK_TYPE_EHRPD;
case ServiceState.RIL_RADIO_TECHNOLOGY_LTE: //在此处做转换
return TelephonyManager.NETWORK_TYPE_LTE;
case ServiceState.RIL_RADIO_TECHNOLOGY_HSPAP:
return TelephonyManager.NETWORK_TYPE_HSPAP;
case ServiceState.RIL_RADIO_TECHNOLOGY_GSM:
return TelephonyManager.NETWORK_TYPE_GSM;
case ServiceState.RIL_RADIO_TECHNOLOGY_TD_SCDMA:
return TelephonyManager.NETWORK_TYPE_TD_SCDMA;
case ServiceState.RIL_RADIO_TECHNOLOGY_IWLAN:
return TelephonyManager.NETWORK_TYPE_IWLAN;
case ServiceState.RIL_RADIO_TECHNOLOGY_LTE_CA:
return TelephonyManager.NETWORK_TYPE_LTE_CA;
default:
return TelephonyManager.NETWORK_TYPE_UNKNOWN;
}
}
ServiceState和TelephonyManager的定义半数以上是不一致的,不过名称上绝大部分是一样的,基本都能一一对应得上。