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

Commit c72a166f authored by Harout Hedeshian's avatar Harout Hedeshian Committed by Linux Build Service Account
Browse files

base: IPV6 tethering support



Added two APIs addUpstreamV6Interface and removeUpstreamV6Interface,
required to pass the interfaces to use to the Router Advertisement
Proxy.
Added a dun entry to the networkAttributes value in
res/values/config.xml.
This is to allow tethering to work with the dunRequired property.
Added dun to allowable tether upstream type.
Enabled debug flags for debug logging inside framework components.
Regardless of MOBILE_TYPE_DUN APN being available, if dun_required
flag is not set, fall back to HIPRI as a preferred APN for the
embedded data call.
Debug logging was enabled by default which was causing security
vulnerabilities. This patch disables debug logging.

CRs-fixed: 555006
Change-Id: Idb0971449473554bcd749d478563db7ba351d55d
Acked-by: default avatarSubash Abhinov Kasiviswanathan <subashab@qti.qualcomm.com>
(cherry picked from commit 43bac130e4bab1c12792d29042f85c6a10372553)
(cherry picked from commit be8491aa9d82177c200eab1af713244a7bbbdcfc)
parent cbbe81cb
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -198,6 +198,16 @@ interface INetworkManagementService
     */
    void disableNat(String internalInterface, String externalInterface);

    /**
     * Add an upstream IPv6 interface
     */
    void addUpstreamV6Interface(String iface);

    /**
     * Remove an upstream IPv6 interface
     */
    void removeUpstreamV6Interface(String iface);

    /**
     ** PPPD
     **/
+2 −0
Original line number Diff line number Diff line
@@ -187,6 +187,7 @@
        <item>"mobile,0,0,0,-1,true"</item>
        <item>"mobile_mms,2,0,2,60000,true"</item>
        <item>"mobile_supl,3,0,2,60000,true"</item>
        <item>"mobile_dun,4,0,2,60000,true"</item>
        <item>"mobile_hipri,5,0,3,60000,true"</item>
        <item>"mobile_fota,10,0,2,60000,true"</item>
        <item>"mobile_ims,11,0,2,60000,true"</item>
@@ -302,6 +303,7 @@
    <integer-array translatable="false" name="config_tether_upstream_types">
        <item>0</item>
        <item>1</item>
        <item>4</item>
        <item>5</item>
        <item>7</item>
        <item>9</item>
+35 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@

package com.android.server;

import static android.Manifest.permission.ACCESS_NETWORK_STATE;
import static android.Manifest.permission.CONNECTIVITY_INTERNAL;
import static android.Manifest.permission.DUMP;
import static android.Manifest.permission.SHUTDOWN;
@@ -59,9 +60,11 @@ import android.os.ServiceManager;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.text.TextUtils;
import android.provider.Settings;
import android.util.Log;
import android.util.Slog;
import android.util.SparseBooleanArray;
import java.util.List;

import com.android.internal.app.IBatteryStats;
import com.android.internal.net.NetworkStatsFactory;
@@ -139,6 +142,7 @@ public class NetworkManagementService extends INetworkManagementService.Stub
        public static final int DnsProxyQueryResult       = 222;
        public static final int ClatdStatusResult         = 223;
        public static final int GetMarkResult             = 225;
        public static final int V6RtrAdvResult            = 227;

        public static final int InterfaceChange           = 600;
        public static final int BandwidthControl          = 601;
@@ -570,6 +574,37 @@ public class NetworkManagementService extends INetworkManagementService.Stub
        }
    }

    @Override
    public void addUpstreamV6Interface(String iface) throws IllegalStateException {
        mContext.enforceCallingOrSelfPermission(
                android.Manifest.permission.ACCESS_NETWORK_STATE, "NetworkManagementService");

        Slog.d(TAG, "addUpstreamInterface("+ iface + ")");
        try {
            final Command cmd = new Command("tether", "interface", "add_upstream");
            cmd.appendArg(iface);
            mConnector.execute(cmd);
        } catch (NativeDaemonConnectorException e) {
            throw new IllegalStateException("Cannot add upstream interface");
        }
    }

    @Override
    public void removeUpstreamV6Interface(String iface) throws IllegalStateException {
        mContext.enforceCallingOrSelfPermission(
                android.Manifest.permission.ACCESS_NETWORK_STATE, "NetworkManagementService");

        Slog.d(TAG, "removeUpstreamInterface(" + iface + ")");

        try {
            final Command cmd = new Command("tether", "interface", "remove_upstream");
            cmd.appendArg(iface);
            mConnector.execute(cmd);
        } catch (NativeDaemonConnectorException e) {
            throw new IllegalStateException("Cannot remove upstream interface");
        }
    }

    @Override
    public InterfaceConfiguration getInterfaceConfig(String iface) {
        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+73 −4
Original line number Diff line number Diff line
@@ -663,12 +663,16 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
                        mUpstreamIfaceTypes.add(HIPRI_TYPE);
                    }
                }
            }
                /* if DUN is still available, make that a priority */
                if (mUpstreamIfaceTypes.contains(DUN_TYPE)) {
                    mPreferredUpstreamMobileApn = ConnectivityManager.TYPE_MOBILE_DUN;
                } else {
                    mPreferredUpstreamMobileApn = ConnectivityManager.TYPE_MOBILE_HIPRI;
                }
            } else {
                /* dun_required is not set, fall back to HIPRI in that case */
                mPreferredUpstreamMobileApn = ConnectivityManager.TYPE_MOBILE_HIPRI;
            }
        }
    }

@@ -1279,6 +1283,51 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
                return true;
            }

            protected void addUpstreamV6Interface(String iface) {
                IBinder b = ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE);
                INetworkManagementService service = INetworkManagementService.Stub.asInterface(b);

                Log.d(TAG, "adding v6 interface " + iface);
                try {
                    service.addUpstreamV6Interface(iface);
                } catch (RemoteException e) {
                    Log.e(TAG, "Unable to append v6 upstream interface");
                }
            }

            protected void removeUpstreamV6Interface(String iface) {
                IBinder b = ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE);
                INetworkManagementService service = INetworkManagementService.Stub.asInterface(b);

                Log.d(TAG, "removing v6 interface " + iface);
                try {
                    service.removeUpstreamV6Interface(iface);
                } catch (RemoteException e) {
                    Log.e(TAG, "Unable to remove v6 upstream interface");
                }
            }


            boolean isIpv6Connected(IConnectivityManager cm, LinkProperties linkProps) {
                boolean ret = false;
                Collection <InetAddress> addresses = null;

                if (cm == null || linkProps == null) {
                    return false;
                }
                addresses = linkProps.getAddresses();
                for (InetAddress addr: addresses) {
                    if (addr instanceof java.net.Inet6Address) {
                        java.net.Inet6Address i6addr = (java.net.Inet6Address) addr;
                        if (!i6addr.isAnyLocalAddress() && !i6addr.isLinkLocalAddress() &&
                                !i6addr.isLoopbackAddress() && !i6addr.isMulticastAddress()) {
                            ret = true;
                            break;
                        }
                    }
                }
                return ret;
            }
            protected void chooseUpstreamType(boolean tryCell) {
                IBinder b = ServiceManager.getService(Context.CONNECTIVITY_SERVICE);
                IConnectivityManager cm = IConnectivityManager.Stub.asInterface(b);
@@ -1297,11 +1346,20 @@ public class Tethering extends INetworkManagementEventObserver.Stub {

                    for (Integer netType : mUpstreamIfaceTypes) {
                        NetworkInfo info = null;
                        LinkProperties props = null;
                        boolean isV6Connected = false;
                        try {
                            info = mConnService.getNetworkInfo(netType.intValue());
                            info = cm.getNetworkInfo(netType.intValue());
                            if (info != null) {
                                props = cm.getLinkProperties(info.getType());
                                isV6Connected = isIpv6Connected(cm, props);
                            }
                        } catch (RemoteException e) { }
                        if ((info != null) && info.isConnected()) {
                            upType = netType.intValue();
                            if (isV6Connected) {
                                addUpstreamV6Interface(props.getInterfaceName());
                            }
                            break;
                        }
                    }
@@ -1491,8 +1549,19 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
                        break;
                    case CMD_UPSTREAM_CHANGED:
                        // need to try DUN immediately if Wifi goes down
                        NetworkInfo info = (NetworkInfo) message.obj;
                        mTryCell = !WAIT_FOR_NETWORK_TO_SETTLE;
                        chooseUpstreamType(mTryCell);
                        if (!info.isConnected()) {
                            IBinder b = ServiceManager.getService(Context.CONNECTIVITY_SERVICE);
                            IConnectivityManager cm = IConnectivityManager.Stub.asInterface(b);
                            try {
                                LinkProperties props = cm.getLinkProperties(info.getType());
                                removeUpstreamV6Interface(props.getInterfaceName());
                            } catch(RemoteException e) {
                                Log.e(TAG, "Exception querying ConnectivityManager", e);
                            }
                        }
                        mTryCell = !mTryCell;
                        break;
                    case CMD_CELL_CONNECTION_RENEW: