summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Nathan Harold <nharold@google.com> 2020-02-20 17:17:36 -0800
committer Nathan Harold <nharold@google.com> 2020-03-25 18:34:06 -0700
commit0f0432c1f6ed99db3a607df63909bc6a2a445506 (patch)
tree9b4c9591d464cc94dab80d00f62fdb171a6a7d53
parent63d4932804a406643d1d124bc88a1a6b956c91aa (diff)
Remove NetworkClass from TelephonyManager
NetworkClass isn't especially useful because the APIs for getting and setting preferred networks have been converted to bitmasks of individual RATs. Removing this because it's causing confusion about the proper structure of the API surface. There are < 100k total usages with the vast majority (60% or more) coming from two apps. Because NetworkClass is used in RadioAccessFamily for a sort of comparison function, rewrite that function, porting and updating logic from TelephonyConnectionService to that compare() method. Bug: 128572818 Test: atest RadioAccessFamilyTest Merged-In: I1f279fadd8c543b845fce0f13dc62c1480757692 Change-Id: I1f279fadd8c543b845fce0f13dc62c1480757692 (cherry picked from commit d44b4efa33d5b17303ae5f4ee43d7096b85e7295)
-rw-r--r--telephony/java/android/telephony/RadioAccessFamily.java48
-rw-r--r--telephony/java/android/telephony/TelephonyManager.java58
2 files changed, 30 insertions, 76 deletions
diff --git a/telephony/java/android/telephony/RadioAccessFamily.java b/telephony/java/android/telephony/RadioAccessFamily.java
index bc8473865466..90ddf2cd4730 100644
--- a/telephony/java/android/telephony/RadioAccessFamily.java
+++ b/telephony/java/android/telephony/RadioAccessFamily.java
@@ -260,24 +260,6 @@ public class RadioAccessFamily implements Parcelable {
return raf;
}
- /**
- * Returns the highest capability of the RadioAccessFamily (4G > 3G > 2G).
- * @param raf The RadioAccessFamily that we wish to filter
- * @return The highest radio capability
- */
- public static int getHighestRafCapability(int raf) {
- if ((LTE & raf) > 0) {
- return TelephonyManager.NETWORK_CLASS_4_G;
- }
- if ((EVDO|HS|WCDMA & raf) > 0) {
- return TelephonyManager.NETWORK_CLASS_3_G;
- }
- if((GSM|CDMA & raf) > 0) {
- return TelephonyManager.NETWORK_CLASS_2_G;
- }
- return TelephonyManager.NETWORK_CLASS_UNKNOWN;
- }
-
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
@PrefNetworkMode
public static int getNetworkTypeFromRaf(int raf) {
@@ -395,4 +377,34 @@ public class RadioAccessFamily implements Parcelable {
}
return result;
}
+
+ /**
+ * Compare two sets of network types to see which is more capable.
+ *
+ * This algorithm first tries to see see if a set has a strict superset of RAT support for
+ * each generation, from newest to oldest; if that results in a tie, then it returns the set
+ * that supports the most RAT types.
+ */
+ public static int compare(long networkTypeBitmaskL, long networkTypeBitmaskR) {
+ final long[] prioritizedNetworkClassBitmasks = new long[] {
+ TelephonyManager.NETWORK_CLASS_BITMASK_5G,
+ TelephonyManager.NETWORK_CLASS_BITMASK_4G,
+ TelephonyManager.NETWORK_CLASS_BITMASK_3G,
+ TelephonyManager.NETWORK_CLASS_BITMASK_2G,
+ };
+
+ long lhsUnique = networkTypeBitmaskL & ~networkTypeBitmaskR;
+ long rhsUnique = networkTypeBitmaskR & ~networkTypeBitmaskL;
+
+ // See if one has a strict super-set of capabilities, generation by generation.
+ for (long classBitmask : prioritizedNetworkClassBitmasks) {
+ int result = 0;
+ if ((lhsUnique & classBitmask) != 0) ++result;
+ if ((rhsUnique & classBitmask) != 0) --result;
+ if (result != 0) return result;
+ }
+
+ // Without a clear winner, return the one that supports the most types.
+ return Long.bitCount(networkTypeBitmaskL) - Long.bitCount(networkTypeBitmaskR);
+ }
}
diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java
index ed674e35b45c..36cf1bd69463 100644
--- a/telephony/java/android/telephony/TelephonyManager.java
+++ b/telephony/java/android/telephony/TelephonyManager.java
@@ -3010,64 +3010,6 @@ public class TelephonyManager {
}
/**
- * Network Class Definitions.
- * Do not change this order, it is used for sorting during emergency calling in
- * {@link TelephonyConnectionService#getFirstPhoneForEmergencyCall()}. Any newer technologies
- * should be added after the current definitions.
- */
- /** Unknown network class. {@hide} */
- public static final int NETWORK_CLASS_UNKNOWN = 0;
- /** Class of broadly defined "2G" networks. {@hide} */
- @UnsupportedAppUsage
- public static final int NETWORK_CLASS_2_G = 1;
- /** Class of broadly defined "3G" networks. {@hide} */
- @UnsupportedAppUsage
- public static final int NETWORK_CLASS_3_G = 2;
- /** Class of broadly defined "4G" networks. {@hide} */
- @UnsupportedAppUsage
- public static final int NETWORK_CLASS_4_G = 3;
- /** Class of broadly defined "5G" networks. {@hide} */
- public static final int NETWORK_CLASS_5_G = 4;
-
- /**
- * Return general class of network type, such as "3G" or "4G". In cases
- * where classification is contentious, this method is conservative.
- *
- * @hide
- */
- @UnsupportedAppUsage
- public static int getNetworkClass(int networkType) {
- switch (networkType) {
- case NETWORK_TYPE_GPRS:
- case NETWORK_TYPE_GSM:
- case NETWORK_TYPE_EDGE:
- case NETWORK_TYPE_CDMA:
- case NETWORK_TYPE_1xRTT:
- case NETWORK_TYPE_IDEN:
- return NETWORK_CLASS_2_G;
- case NETWORK_TYPE_UMTS:
- case NETWORK_TYPE_EVDO_0:
- case NETWORK_TYPE_EVDO_A:
- case NETWORK_TYPE_HSDPA:
- case NETWORK_TYPE_HSUPA:
- case NETWORK_TYPE_HSPA:
- case NETWORK_TYPE_EVDO_B:
- case NETWORK_TYPE_EHRPD:
- case NETWORK_TYPE_HSPAP:
- case NETWORK_TYPE_TD_SCDMA:
- return NETWORK_CLASS_3_G;
- case NETWORK_TYPE_LTE:
- case NETWORK_TYPE_IWLAN:
- case NETWORK_TYPE_LTE_CA:
- return NETWORK_CLASS_4_G;
- case NETWORK_TYPE_NR:
- return NETWORK_CLASS_5_G;
- default:
- return NETWORK_CLASS_UNKNOWN;
- }
- }
-
- /**
* Returns a string representation of the radio technology (network type)
* currently in use on the device.
* @return the name of the radio technology