Don't call maybeTrackInterface on the wrong thread. am: 6123533817

Change-Id: Idc00a7e5520ccae2db848d729f0fe80aab724468
This commit is contained in:
Lorenzo Colitti
2020-04-22 08:32:54 +00:00
committed by Automerger Merge Worker

View File

@@ -193,9 +193,11 @@ final class EthernetTracker {
} }
public void setIncludeTestInterfaces(boolean include) { public void setIncludeTestInterfaces(boolean include) {
mIncludeTestInterfaces = include; mHandler.post(() -> {
updateIfaceMatchRegexp(); mIncludeTestInterfaces = include;
trackAvailableInterfaces(); updateIfaceMatchRegexp();
mHandler.post(() -> trackAvailableInterfaces());
});
} }
public void requestTetheredInterface(ITetheredInterfaceCallback callback) { public void requestTetheredInterface(ITetheredInterfaceCallback callback) {
@@ -307,7 +309,7 @@ final class EthernetTracker {
ipConfiguration = createDefaultIpConfiguration(); ipConfiguration = createDefaultIpConfiguration();
} }
Log.d(TAG, "Started tracking interface " + iface); Log.d(TAG, "Tracking interface in client mode: " + iface);
mFactory.addInterface(iface, hwAddress, nc, ipConfiguration); mFactory.addInterface(iface, hwAddress, nc, ipConfiguration);
} else { } else {
maybeUpdateServerModeInterfaceState(iface, true); maybeUpdateServerModeInterfaceState(iface, true);
@@ -349,6 +351,9 @@ final class EthernetTracker {
private void maybeUpdateServerModeInterfaceState(String iface, boolean available) { private void maybeUpdateServerModeInterfaceState(String iface, boolean available) {
if (available == mTetheredInterfaceWasAvailable || !iface.equals(mDefaultInterface)) return; if (available == mTetheredInterfaceWasAvailable || !iface.equals(mDefaultInterface)) return;
Log.d(TAG, (available ? "Tracking" : "No longer tracking")
+ " interface in server mode: " + iface);
final int pendingCbs = mTetheredInterfaceRequests.beginBroadcast(); final int pendingCbs = mTetheredInterfaceRequests.beginBroadcast();
for (int i = 0; i < pendingCbs; i++) { for (int i = 0; i < pendingCbs; i++) {
ITetheredInterfaceCallback item = mTetheredInterfaceRequests.getBroadcastItem(i); ITetheredInterfaceCallback item = mTetheredInterfaceRequests.getBroadcastItem(i);
@@ -363,14 +368,18 @@ final class EthernetTracker {
} }
private void maybeTrackInterface(String iface) { private void maybeTrackInterface(String iface) {
if (DBG) Log.i(TAG, "maybeTrackInterface " + iface); if (!iface.matches(mIfaceMatch)) {
// If we don't already track this interface, and if this interface matches
// our regex, start tracking it.
if (!iface.matches(mIfaceMatch) || mFactory.hasInterface(iface)
|| iface.equals(mDefaultInterface)) {
return; return;
} }
// If we don't already track this interface, and if this interface matches
// our regex, start tracking it.
if (mFactory.hasInterface(iface) || iface.equals(mDefaultInterface)) {
if (DBG) Log.w(TAG, "Ignoring already-tracked interface " + iface);
return;
}
if (DBG) Log.i(TAG, "maybeTrackInterface: " + iface);
// TODO: avoid making an interface default if it has configured NetworkCapabilities. // TODO: avoid making an interface default if it has configured NetworkCapabilities.
if (mDefaultInterface == null) { if (mDefaultInterface == null) {
mDefaultInterface = iface; mDefaultInterface = iface;