Android 源码 判断网络数据类型

时间:2023-03-09 15:48:32
Android 源码 判断网络数据类型

private final void updateDataNetType(int slotId) {
int tempDataNetType;
NetworkType tempDataNetType3G = NetworkType.Type_G;

if (slotId == Phone.GEMINI_SIM_1) {
tempDataNetType = mDataNetType;
} else {
tempDataNetType = mDataNetTypeGemini;
}
Xlog.d(TAG, "updateDataNetType(" + slotId + "), DataNetType=" + tempDataNetType + ".");

int simColorId = SIMHelper.getSIMColorIdBySlot(mContext, slotId);
if (simColorId == -1) {
return;
}
Xlog.d(TAG, "updateDataNetType(" + slotId + "), simColorId=" + simColorId);

boolean tempIsRoaming = false;
if ((isCdma(slotId) && isCdmaEri(slotId))
|| mPhone.isNetworkRoamingGemini(slotId)) {
int tempRoamingId = 0;

if (simColorId > -1 && simColorId < 4) {
tempRoamingId = TelephonyIconsGemini.ROAMING[simColorId];
}
Xlog.d(TAG, "updateDataNetType(" + slotId + ") RoamingresId= " + tempRoamingId + " simColorId = " + simColorId);
if (slotId == Phone.GEMINI_SIM_1) {
mIsRoaming = true;
mIsRoamingId = tempRoamingId;
} else {
mIsRoamingGemini = true;
mIsRoamingGeminiId = tempRoamingId;
}
tempIsRoaming = true;
} else {
if (slotId == Phone.GEMINI_SIM_1) {
mIsRoaming = false;
mIsRoamingId = 0;
} else {
mIsRoamingGemini = false;
mIsRoamingGeminiId = 0;
}
}

DataType tempDateType;

String tempContentDescriptionDataType;
if (mIsWimaxEnabled && mWimaxConnected) {
// wimax is a special 4g network not handled by telephony
tempDateType = DataType.Type_4G;
tempContentDescriptionDataType = mContext.getString(
R.string.accessibility_data_connection_4g);
} else {
switch (tempDataNetType) {
case TelephonyManager.NETWORK_TYPE_UNKNOWN:
if (!mShowAtLeastThreeGees) {
tempDateType = DataType.Type_G;
tempContentDescriptionDataType = mContext.getString(
R.string.accessibility_data_connection_gprs);
break;
} else {
// fall through
}
case TelephonyManager.NETWORK_TYPE_EDGE:
if (!mShowAtLeastThreeGees) {
tempDateType = DataType.Type_E;
tempContentDescriptionDataType = mContext.getString(
R.string.accessibility_data_connection_edge);
break;
} else {
// fall through
}
case TelephonyManager.NETWORK_TYPE_UMTS:
tempDataNetType3G = NetworkType.Type_3G;
tempDateType = DataType.Type_3G;
tempContentDescriptionDataType = mContext.getString(
R.string.accessibility_data_connection_3g);
break;
case TelephonyManager.NETWORK_TYPE_HSDPA:
case TelephonyManager.NETWORK_TYPE_HSUPA:
case TelephonyManager.NETWORK_TYPE_HSPA:
case TelephonyManager.NETWORK_TYPE_HSPAP:
tempDataNetType3G = NetworkType.Type_3G;
if (mHspaDataDistinguishable) {
tempDateType = DataType.Type_H;
tempContentDescriptionDataType = mContext.getString(
R.string.accessibility_data_connection_3_5g);
} else {
tempDateType = DataType.Type_3G;
tempContentDescriptionDataType = mContext.getString(
R.string.accessibility_data_connection_3g);
}
break;
case TelephonyManager.NETWORK_TYPE_CDMA:
// display 1xRTT for IS95A/B
tempDataNetType3G = NetworkType.Type_1X;
tempDateType = DataType.Type_1X;
tempContentDescriptionDataType = mContext.getString(
R.string.accessibility_data_connection_cdma);
break;
case TelephonyManager.NETWORK_TYPE_1xRTT:
tempDataNetType3G = NetworkType.Type_1X;
tempDateType = DataType.Type_1X;
tempContentDescriptionDataType = mContext.getString(
R.string.accessibility_data_connection_cdma);
break;
case TelephonyManager.NETWORK_TYPE_EVDO_0: //fall through
case TelephonyManager.NETWORK_TYPE_EVDO_A:
case TelephonyManager.NETWORK_TYPE_EVDO_B:
case TelephonyManager.NETWORK_TYPE_EHRPD:
tempDataNetType3G = NetworkType.Type_1X3G;
tempDateType = DataType.Type_3G;
tempContentDescriptionDataType = mContext.getString(
R.string.accessibility_data_connection_3g);
break;
case TelephonyManager.NETWORK_TYPE_LTE:
tempDateType = DataType.Type_4G;
tempContentDescriptionDataType = mContext.getString(
R.string.accessibility_data_connection_4g);
break;
default:
if (!mShowAtLeastThreeGees) {
tempDataNetType3G = NetworkType.Type_G;
tempDateType = DataType.Type_G;
tempContentDescriptionDataType = mContext.getString(
R.string.accessibility_data_connection_gprs);
} else {
tempDataNetType3G = NetworkType.Type_3G;
tempDateType = DataType.Type_3G;
tempContentDescriptionDataType = mContext.getString(
R.string.accessibility_data_connection_3g);
}
break;
}
}