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

Commit 4d525cbe authored by Mike Kasick's avatar Mike Kasick
Browse files

Keep track of tetherable USB interfaces in both up and down link states.

USB network interfaces that are present-since-boot are never issued "added"
(or "removed", for that matter) notifications from netd, and thus, are only
discovered by Tethering when their link state changes.  Prior to this
commit, such interfaces were only tracked on change to "up" link state,
even though the interfaces were _not_ removed on changes to "down" state.

On some devices (e.g., epicmtd) a change to "up" state only occurs after
(i) IFF_UP is set on the interface, (ii) the rndis USB gadget function is
enabled, and (iii) a USB cable is connected to another machine.  Since
rndis is enabled immediately before the start of USB tethering, the "up"
state is achieved asynchronously, and often _after_ Tethering looks for a
tetherable interface.  However, "down" state is synchronously reported when
IFF_UP is set, and thus, serves as an effective mechanism to notify
Tethering about the existence of the interface.
parent f8a78d0a
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -218,18 +218,18 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
            if (found == false) return;

            TetherInterfaceSM sm = mIfaces.get(iface);
            if (up) {
            if (up || usb) {
                // Present-at-boot USB interfaces are discovered here, and only go up after
                // RNDIS is enabled and a link is established.  Keep track of USB
                // interfaces even if they're in the down state, to avoid a race between
                // tetherUsb(true) and when the link actually goes up.
                if (sm == null) {
                    sm = new TetherInterfaceSM(iface, mLooper, usb);
                    mIfaces.put(iface, sm);
                    sm.start();
                }
            } else {
                if (isUsb(iface)) {
                    // ignore usb0 down after enabling RNDIS
                    // we will handle disconnect in interfaceRemoved instead
                    if (VDBG) Log.d(TAG, "ignore interface down for " + iface);
                } else if (sm != null) {
                if (sm != null) {
                    sm.sendMessage(TetherInterfaceSM.CMD_INTERFACE_DOWN);
                    mIfaces.remove(iface);
                }