Use OO Methods for CellIdentity Instead of RTTI
Minor cleanup now that we support OO access to
CellIdentity and CellSignalStrength from CellInfo.
Bug: 67711865
Test: manual
Change-Id: Ia4f27f299b96bb5e3f6971ce49ae0e7f2a477eb8
diff --git a/src/com/android/phone/CellInfoUtil.java b/src/com/android/phone/CellInfoUtil.java
index 2c5f2a8..462cafe 100644
--- a/src/com/android/phone/CellInfoUtil.java
+++ b/src/com/android/phone/CellInfoUtil.java
@@ -26,7 +26,6 @@
import android.telephony.CellInfoGsm;
import android.telephony.CellInfoLte;
import android.telephony.CellInfoWcdma;
-import android.telephony.TelephonyManager;
import android.text.BidiFormatter;
import android.text.TextDirectionHeuristics;
import android.text.TextUtils;
@@ -47,47 +46,6 @@
}
/**
- * Get the network type from a CellInfo. Network types include
- * {@link TelephonyManager#NETWORK_TYPE_LTE}, {@link TelephonyManager#NETWORK_TYPE_UMTS},
- * {@link TelephonyManager#NETWORK_TYPE_GSM}, {@link TelephonyManager#NETWORK_TYPE_CDMA} and
- * {@link TelephonyManager#NETWORK_TYPE_UNKNOWN}
- * @return network types
- */
- public static int getNetworkType(CellInfo cellInfo) {
- if (cellInfo instanceof CellInfoLte) {
- return TelephonyManager.NETWORK_TYPE_LTE;
- } else if (cellInfo instanceof CellInfoWcdma) {
- return TelephonyManager.NETWORK_TYPE_UMTS;
- } else if (cellInfo instanceof CellInfoGsm) {
- return TelephonyManager.NETWORK_TYPE_GSM;
- } else if (cellInfo instanceof CellInfoCdma) {
- return TelephonyManager.NETWORK_TYPE_CDMA;
- } else {
- Log.e(TAG, "Invalid CellInfo type");
- return TelephonyManager.NETWORK_TYPE_UNKNOWN;
- }
- }
-
- /**
- * Get signal level as an int from 0..4.
- * @return Signal strength level
- */
- public static int getLevel(CellInfo cellInfo) {
- if (cellInfo instanceof CellInfoLte) {
- return ((CellInfoLte) cellInfo).getCellSignalStrength().getLevel();
- } else if (cellInfo instanceof CellInfoWcdma) {
- return ((CellInfoWcdma) cellInfo).getCellSignalStrength().getLevel();
- } else if (cellInfo instanceof CellInfoGsm) {
- return ((CellInfoGsm) cellInfo).getCellSignalStrength().getLevel();
- } else if (cellInfo instanceof CellInfoCdma) {
- return ((CellInfoCdma) cellInfo).getCellSignalStrength().getLevel();
- } else {
- Log.e(TAG, "Invalid CellInfo type");
- return 0;
- }
- }
-
- /**
* Wrap a CellIdentity into a CellInfo.
*/
public static CellInfo wrapCellInfoWithCellIdentity(CellIdentity cellIdentity) {
diff --git a/src/com/android/phone/NetworkOperatorPreference.java b/src/com/android/phone/NetworkOperatorPreference.java
index 85adf16..e582924 100644
--- a/src/com/android/phone/NetworkOperatorPreference.java
+++ b/src/com/android/phone/NetworkOperatorPreference.java
@@ -24,7 +24,6 @@
import android.preference.Preference;
import android.telephony.CellInfo;
import android.telephony.SignalStrength;
-import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.Gravity;
@@ -71,7 +70,7 @@
networkTitle += " " + getContext().getResources().getString(R.string.forbidden_network);
}
setTitle(networkTitle);
- int level = CellInfoUtil.getLevel(mCellInfo);
+ int level = mCellInfo.getCellSignalStrength().getLevel();
if (DBG) Log.d(TAG, "refresh level: " + String.valueOf(level));
if (mLevel != level) {
mLevel = level;
@@ -86,17 +85,15 @@
updateIcon(level);
}
- private int getIconId(int networkType) {
- if (networkType == TelephonyManager.NETWORK_TYPE_CDMA) {
- return R.drawable.signal_strength_1x;
- } else if (networkType == TelephonyManager.NETWORK_TYPE_LTE) {
- return R.drawable.signal_strength_lte;
- } else if (networkType == TelephonyManager.NETWORK_TYPE_UMTS) {
- return R.drawable.signal_strength_3g;
- } else if (networkType == TelephonyManager.NETWORK_TYPE_GSM) {
- return R.drawable.signal_strength_g;
- } else {
- return 0;
+ private static int getIconIdForCell(CellInfo ci) {
+ final int type = ci.getCellIdentity().getType();
+ switch (type) {
+ case CellInfo.TYPE_GSM: return R.drawable.signal_strength_g;
+ case CellInfo.TYPE_WCDMA: // fall through
+ case CellInfo.TYPE_TDSCDMA: return R.drawable.signal_strength_3g;
+ case CellInfo.TYPE_LTE: return R.drawable.signal_strength_lte;
+ case CellInfo.TYPE_CDMA: return R.drawable.signal_strength_1x;
+ default: return 0;
}
}
@@ -113,7 +110,7 @@
signalDrawable.setDarkIntensity(0);
// Make the network type drawable
- int iconType = getIconId(CellInfoUtil.getNetworkType(mCellInfo));
+ int iconType = getIconIdForCell(mCellInfo);
Drawable networkDrawable =
iconType == NO_CELL_DATA_CONNECTED_ICON
? EMPTY_DRAWABLE
diff --git a/src/com/android/phone/NetworkSelectSetting.java b/src/com/android/phone/NetworkSelectSetting.java
index 96e4a26..6bb42c8 100644
--- a/src/com/android/phone/NetworkSelectSetting.java
+++ b/src/com/android/phone/NetworkSelectSetting.java
@@ -560,8 +560,8 @@
map.put(plmn, cellInfo);
} else {
if (map.get(plmn).isRegistered()
- || CellInfoUtil.getLevel(map.get(plmn))
- > CellInfoUtil.getLevel(cellInfo)) {
+ || map.get(plmn).getCellSignalStrength().getLevel()
+ > cellInfo.getCellSignalStrength().getLevel()) {
// Skip if the stored cellInfo is registered or has higher signal strength level
continue;
}