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

Commit 5257ebe2 authored by Sagar Regmi's avatar Sagar Regmi Committed by Steve Kondik
Browse files

Broadcast tethered client inteface along with upstream interface name

On change in tethering upstream interface for IPV4 of IPV6 address,
broadcast an intent with both tethered client interface as well as
upstream interface name, ip address type and update type.

Change-Id: I2f23e2b8ec125339bedd454446accb23e33cacae
parent bece9206
Loading
Loading
Loading
Loading
+41 −17
Original line number Diff line number Diff line
@@ -67,6 +67,9 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;

import static libcore.io.OsConstants.AF_INET;
import static libcore.io.OsConstants.AF_INET6;

/**
 * @hide
 *
@@ -86,9 +89,12 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
    public static final String UPSTREAM_IFACE_CHANGED_ACTION =
                         "com.android.server.connectivity.UPSTREAM_IFACE_CHANGED";

    // Upstream Interface Name i.e rmnet_data0, wlan0 etc
    // Upstream Interface Name i.e. rmnet_data0, wlan0 etc.
    public static final String EXTRA_UPSTREAM_IFACE = "tetheringUpstreamIface";

    // Tethered Interface Name i.e. rndis0, wlan0, usb0 etc.
    public static final String EXTRA_TETHERED_IFACE = "tetheredClientIface";

    // Upstream Interface IP Type i.e IPV6 or IPV4
    public static final String EXTRA_UPSTREAM_IP_TYPE = "tetheringUpstreamIpType";

@@ -98,8 +104,6 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
    // Default Value for Extra Infomration
    public static final int EXTRA_UPSTREAM_INFO_DEFAULT = -1;

    private enum IPAddrType { V4, V6 }

    private enum UpstreamInfoUpdateType {
        UPSTREAM_IFACE_REMOVED,
        UPSTREAM_IFACE_ADDED
@@ -504,17 +508,19 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
        }
    }

    private void sendUpstreamIfaceChangeBroadcast( String upstreamIface,
                                                   IPAddrType ip_type, UpstreamInfoUpdateType update_type) {
    private void sendUpstreamIfaceChangeBroadcast( String upstreamIface, String tetheredIface,
                                                   int ip_type,
                                                   UpstreamInfoUpdateType update_type) {
        if (DBG) Log.d(TAG, "sendUpstreamIfaceChangeBroadcast upstreamIface:" + upstreamIface +
                            " tetheredIface:" + tetheredIface +
                            " IP Type: "+ ip_type + " update_type" + update_type);
        Intent intent = new Intent(UPSTREAM_IFACE_CHANGED_ACTION);
        intent.putExtra(EXTRA_UPSTREAM_IFACE, upstreamIface);
        intent.putExtra(EXTRA_UPSTREAM_IP_TYPE, ip_type.ordinal());
        intent.putExtra(EXTRA_TETHERED_IFACE, tetheredIface);
        intent.putExtra(EXTRA_UPSTREAM_IP_TYPE, ip_type);
        intent.putExtra(EXTRA_UPSTREAM_UPDATE_TYPE, update_type.ordinal());

        mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
        if (VDBG) Log.d(TAG, "sendUpstreamIfaceChangeBroadcast: Intent broadcasted");
    }
    private void showTetheredNotification(int icon) {
        NotificationManager notificationManager =
@@ -932,6 +938,12 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
            }
        }

        public String getTethered() {
            synchronized (Tethering.this.mPublicSync) {
                return mIfaceName;
            }
        }

        private void setTethered(boolean tethered) {
            synchronized (Tethering.this.mPublicSync) {
                mTethered = tethered;
@@ -1063,9 +1075,12 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
                        if (VDBG) Log.e(TAG, "Exception in forceUpdate: " + e.toString());
                    }
                    try {
                        if(VDBG) Log.d(TAG, "Disabling NAT - Tethered Iface = " + mIfaceName +
                                            " mMyUpstreamIfaceName= " + mMyUpstreamIfaceName);
                        mNMService.disableNat(mIfaceName, mMyUpstreamIfaceName);
                        // Send intent to CNE Service
                        sendUpstreamIfaceChangeBroadcast( mMyUpstreamIfaceName, IPAddrType.V4,
                        sendUpstreamIfaceChangeBroadcast( mMyUpstreamIfaceName,
                                                     mIfaceName,
                                                     AF_INET,
                                                     UpstreamInfoUpdateType.UPSTREAM_IFACE_REMOVED);
                    } catch (Exception e) {
                        if (VDBG) Log.e(TAG, "Exception in disableNat: " + e.toString());
@@ -1117,9 +1132,13 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
                        cleanupUpstream();
                        if (newUpstreamIfaceName != null) {
                            try {
                                if(VDBG) Log.d(TAG,"Enabling NAT - Tethered Iface = " + mIfaceName +
                                                   " newUpstreamIfaceName =" +newUpstreamIfaceName);
                                mNMService.enableNat(mIfaceName, newUpstreamIfaceName);
                                // Send intent to CNE Service
                                sendUpstreamIfaceChangeBroadcast( newUpstreamIfaceName, IPAddrType.V4,
                                sendUpstreamIfaceChangeBroadcast(
                                                       newUpstreamIfaceName,
                                                       mIfaceName,
                                                       AF_INET,
                                                       UpstreamInfoUpdateType.UPSTREAM_IFACE_ADDED);
                            } catch (Exception e) {
                                Log.e(TAG, "Exception enabling Nat: " + e.toString());
@@ -1374,8 +1393,10 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
                Log.d(TAG, "adding v6 interface " + iface);
                try {
                    service.addUpstreamV6Interface(iface);
                    sendUpstreamIfaceChangeBroadcast( iface, IPAddrType.V6,
                    for (TetherInterfaceSM sm : mNotifyList) {
                        sendUpstreamIfaceChangeBroadcast( iface, sm.getTethered(), AF_INET6,
                                UpstreamInfoUpdateType.UPSTREAM_IFACE_ADDED);
                    }
                } catch (RemoteException e) {
                    Log.e(TAG, "Unable to append v6 upstream interface");
                }
@@ -1388,8 +1409,10 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
                Log.d(TAG, "removing v6 interface " + iface);
                try {
                    service.removeUpstreamV6Interface(iface);
                    sendUpstreamIfaceChangeBroadcast( iface, IPAddrType.V6,
                    for (TetherInterfaceSM sm : mNotifyList) {
                        sendUpstreamIfaceChangeBroadcast( iface, sm.getTethered(), AF_INET6,
                                UpstreamInfoUpdateType.UPSTREAM_IFACE_REMOVED);
                    }
                } catch (RemoteException e) {
                    Log.e(TAG, "Unable to remove v6 upstream interface");
                }
@@ -1619,6 +1642,7 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
                        }
                        break;
                    case CMD_UPSTREAM_CHANGED:
                        if(VDBG) Log.d(TAG, "CMD_UPSTREAM_CHANGED event received");
                        // need to try DUN immediately if Wifi goes down
                        NetworkInfo info = (NetworkInfo) message.obj;
                        mTryCell = !WAIT_FOR_NETWORK_TO_SETTLE;