summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLorenzo Colitti <lorenzo@google.com>2020-03-19 15:52:03 +0000
committerLorenzo Colitti <lorenzo@google.com>2020-03-19 15:53:13 +0000
commitbbb550ceb7e22bbfb730cc83011ec2498eb08b6c (patch)
tree0a2fec897425377986fe2e17fa9d6aac054a0a28
parentfb800f0d889fbec1c3211f20b4e2d7a2e6b4d657 (diff)
downloadethernet-bbb550ceb7e22bbfb730cc83011ec2498eb08b6c.tar.gz
Support setting the default interface to null again.
Currently, the default interface can only ever go from null to non-null. This is correct for fixed interfaces (because they don't get unplugged) and it's generally correct for USB interfaces that use ethX as their device name (because when they are unplugged and plugged in again, the device name won't change). But it is not correct if, for example, the default interface is a test interface. So, allow mDefaultInterface to go back to null. This CL also fixes a crash if a tethered interface request is added and removed when there is no default interface. Also, make dump() report tethered interface requests. Also remove an unused variable that I missed in the previous CL. Bug: 150644681 Test: tested by EthernetTetheringTest in same topic Change-Id: I5109d8da3aeb6c1f6523291d9e2ec92c64b5ad2d Merged-In: I5109d8da3aeb6c1f6523291d9e2ec92c64b5ad2d (cherry picked from commit cc156c2f7793731b2699e194d4b164138ee4cf62)
-rw-r--r--java/com/android/server/ethernet/EthernetTracker.java24
1 files changed, 16 insertions, 8 deletions
diff --git a/java/com/android/server/ethernet/EthernetTracker.java b/java/com/android/server/ethernet/EthernetTracker.java
index 91453ab..d1f1402 100644
--- a/java/com/android/server/ethernet/EthernetTracker.java
+++ b/java/com/android/server/ethernet/EthernetTracker.java
@@ -240,17 +240,17 @@ final class EthernetTracker {
private void maybeUntetherDefaultInterface() {
if (mTetheredInterfaceRequests.getRegisteredCallbackCount() > 0) return;
- // mDefaultInterface null means that there never was a default interface (it is never set
- // to null).
- if (mDefaultInterfaceMode == INTERFACE_MODE_CLIENT || mDefaultInterface == null) return;
-
+ if (mDefaultInterfaceMode == INTERFACE_MODE_CLIENT) return;
setDefaultInterfaceMode(INTERFACE_MODE_CLIENT);
}
private void setDefaultInterfaceMode(int mode) {
+ Log.d(TAG, "Setting default interface mode to " + mode);
mDefaultInterfaceMode = mode;
- removeInterface(mDefaultInterface);
- addInterface(mDefaultInterface);
+ if (mDefaultInterface != null) {
+ removeInterface(mDefaultInterface);
+ addInterface(mDefaultInterface);
+ }
}
private int getInterfaceMode(final String iface) {
@@ -264,6 +264,13 @@ final class EthernetTracker {
mFactory.removeInterface(iface);
}
+ private void stopTrackingInterface(String iface) {
+ removeInterface(iface);
+ if (iface.equals(mDefaultInterface)) {
+ mDefaultInterface = null;
+ }
+ }
+
private void addInterface(String iface) {
InterfaceConfiguration config = null;
// Bring up the interface so we get link status indications.
@@ -406,7 +413,7 @@ final class EthernetTracker {
@Override
public void interfaceRemoved(String iface) {
- mHandler.post(() -> removeInterface(iface));
+ mHandler.post(() -> stopTrackingInterface(iface));
}
}
@@ -585,7 +592,6 @@ final class EthernetTracker {
}
private void updateIfaceMatchRegexp() {
- final String testInterfaceMatch = TEST_TAP_PREFIX + ".*";
final String match = mContext.getResources().getString(
com.android.internal.R.string.config_ethernet_iface_regex);
mIfaceMatch = mIncludeTestInterfaces
@@ -604,6 +610,8 @@ final class EthernetTracker {
pw.println("Ethernet interface name filter: " + mIfaceMatch);
pw.println("Default interface: " + mDefaultInterface);
pw.println("Default interface mode: " + mDefaultInterfaceMode);
+ pw.println("Tethered interface requests: "
+ + mTetheredInterfaceRequests.getRegisteredCallbackCount());
pw.println("Listeners: " + mListeners.getRegisteredCallbackCount());
pw.println("IP Configurations:");
pw.increaseIndent();