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

Commit 43d14a4f authored by Sagar Regmi's avatar Sagar Regmi Committed by Steve Kondik
Browse files

tether: tethering chooses wrong upstream when mobile_dun is required

When mobile_dun is required, the default mobile type will
be deleted from upstream list, this makes wifi become
the highest priority upstream even whne wifi is not available.

Change-Id: I2c12f6cd6d52331220dce900609ad072f9ec3fbc
CRs-fixed: 671675
parent 5a30e8a0
Loading
Loading
Loading
Loading
+20 −11
Original line number Diff line number Diff line
@@ -115,6 +115,7 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
    private Object mPublicSync;

    private static final Integer MOBILE_TYPE = new Integer(ConnectivityManager.TYPE_MOBILE);
    private static final Integer WIFI_TYPE = new Integer(ConnectivityManager.TYPE_WIFI);
    private static final Integer HIPRI_TYPE = new Integer(ConnectivityManager.TYPE_MOBILE_HIPRI);
    private static final Integer DUN_TYPE = new Integer(ConnectivityManager.TYPE_MOBILE_DUN);

@@ -223,24 +224,32 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
        Collection<Integer> upstreamIfaceTypes = new ArrayList();
        IBinder b = ServiceManager.getService(Context.CONNECTIVITY_SERVICE);
        IConnectivityManager cm = IConnectivityManager.Stub.asInterface(b);

        int activeNetType = ConnectivityManager.TYPE_NONE;
        try {
            NetworkInfo networkInfo = cm.getActiveNetworkInfo();
            if (networkInfo != null) {
                int activeNetType = networkInfo.getType();
            activeNetType = cm.getActiveNetworkInfo().getType();
        } catch (Exception e) {
            Log.d(TAG, "exception when get active network info:" + e);
        }

        for (int i : ifaceTypes) {
            if (i == activeNetType) {
                upstreamIfaceTypes.add(new Integer(i));
            }
        }
            }
        } catch (Exception e) {
            Log.d(TAG, "Exception adding default nw to upstreamIfaceTypes: " + e);
        }

        for (int i : ifaceTypes) {
            if (!upstreamIfaceTypes.contains(new Integer(i))) {
                upstreamIfaceTypes.add(new Integer(i));
            }
        }
        if ((activeNetType == ConnectivityManager.TYPE_MOBILE)
                && upstreamIfaceTypes.contains(WIFI_TYPE)) {
            upstreamIfaceTypes.remove(WIFI_TYPE);
        } else if ((activeNetType == ConnectivityManager.TYPE_WIFI)
                && upstreamIfaceTypes.contains(MOBILE_TYPE)) {
            upstreamIfaceTypes.remove(MOBILE_TYPE);
        }

        synchronized (mPublicSync) {
            mTetherableUsbRegexs = tetherableUsbRegexs;