2022년 5월 31일 화요일

How to make WiFi higher priority than Ethernet on android?

 1. Android 9


frameworks/opt/net/ethernet/java/com/android/server/ethernet/EthernetNetworkFactory.java



/**

 * {@link NetworkFactory} that represents Ethernet networks.

 *

 * This class reports a static network score of 70 when it is tracking an interface and that

 * interface's link is up, and a score of 0 otherwise.

 */

public class EthernetNetworkFactory extends NetworkFactory {

    private final static String TAG = EthernetNetworkFactory.class.getSimpleName();

    final static boolean DBG = true;


    private static final int NETWORK_SCORE = 59;// fix to lower score than 60.


2. Android 11

frameworks/opt/net/ethernet/java/com/android/server/ethernet/EthernetNetworkFactory.java

        private static final SparseArray<TransportInfo> sTransports = new SparseArray();

        static {

            // LowpanInterfaceTracker.NETWORK_SCORE

            sTransports.put(NetworkCapabilities.TRANSPORT_LOWPAN,

                    new TransportInfo(ConnectivityManager.TYPE_NONE, 30));

            // WifiAwareDataPathStateManager.NETWORK_FACTORY_SCORE_AVAIL

            sTransports.put(NetworkCapabilities.TRANSPORT_WIFI_AWARE,

                    new TransportInfo(ConnectivityManager.TYPE_NONE, 1));

            // EthernetNetworkFactory.NETWORK_SCORE

            sTransports.put(NetworkCapabilities.TRANSPORT_ETHERNET,

                    new TransportInfo(ConnectivityManager.TYPE_ETHERNET, /*70*/55));