Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0f0432c1 authored by Nathan Harold's avatar Nathan Harold
Browse files

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 d44b4efa)
parent 63d49328
Loading
Loading
Loading
Loading
+30 −18
Original line number Diff line number Diff line
@@ -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);
    }
}
+0 −58
Original line number Diff line number Diff line
@@ -3009,64 +3009,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.