Merge "Minor upstream selection refactoring"

am: 12fe022fbd

Change-Id: I1984cf520c04cdc2751dca3d6029793a257a1592
This commit is contained in:
Erik Kline
2017-06-05 04:28:16 +00:00
committed by android-build-merger
2 changed files with 24 additions and 41 deletions

View File

@@ -18,6 +18,7 @@ package com.android.server.connectivity;
import static android.hardware.usb.UsbManager.USB_CONNECTED; import static android.hardware.usb.UsbManager.USB_CONNECTED;
import static android.hardware.usb.UsbManager.USB_FUNCTION_RNDIS; import static android.hardware.usb.UsbManager.USB_FUNCTION_RNDIS;
import static android.net.ConnectivityManager.getNetworkTypeName;
import static android.net.wifi.WifiManager.EXTRA_WIFI_AP_INTERFACE_NAME; import static android.net.wifi.WifiManager.EXTRA_WIFI_AP_INTERFACE_NAME;
import static android.net.wifi.WifiManager.EXTRA_WIFI_AP_MODE; import static android.net.wifi.WifiManager.EXTRA_WIFI_AP_MODE;
import static android.net.wifi.WifiManager.EXTRA_WIFI_AP_STATE; import static android.net.wifi.WifiManager.EXTRA_WIFI_AP_STATE;
@@ -241,8 +242,10 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering
return (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); return (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
} }
// NOTE: This is always invoked on the mLooper thread.
private void updateConfiguration() { private void updateConfiguration() {
mConfig = new TetheringConfiguration(mContext, mLog); mConfig = new TetheringConfiguration(mContext, mLog);
mUpstreamNetworkMonitor.updateMobileRequiresDun(mConfig.isDunRequired);
} }
@Override @Override
@@ -1179,15 +1182,6 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering
return false; return false;
} }
protected void requestUpstreamMobileConnection() {
mUpstreamNetworkMonitor.updateMobileRequiresDun(mConfig.isDunRequired);
mUpstreamNetworkMonitor.registerMobileNetworkRequest();
}
protected void unrequestUpstreamMobileConnection() {
mUpstreamNetworkMonitor.releaseMobileNetworkRequest();
}
protected boolean turnOnMasterTetherSettings() { protected boolean turnOnMasterTetherSettings() {
final TetheringConfiguration cfg = mConfig; final TetheringConfiguration cfg = mConfig;
try { try {
@@ -1236,17 +1230,26 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering
} }
protected void chooseUpstreamType(boolean tryCell) { protected void chooseUpstreamType(boolean tryCell) {
final int upstreamType = findPreferredUpstreamType(tryCell); updateConfiguration(); // TODO - remove?
final int upstreamType = findPreferredUpstreamType(
getConnectivityManager(), mConfig);
if (upstreamType == ConnectivityManager.TYPE_NONE) {
if (tryCell) {
mUpstreamNetworkMonitor.registerMobileNetworkRequest();
// We think mobile should be coming up; don't set a retry.
} else {
sendMessageDelayed(CMD_RETRY_UPSTREAM, UPSTREAM_SETTLE_TIME_MS);
}
}
setUpstreamByType(upstreamType); setUpstreamByType(upstreamType);
} }
protected int findPreferredUpstreamType(boolean tryCell) { // TODO: Move this function into UpstreamNetworkMonitor.
final ConnectivityManager cm = getConnectivityManager(); protected int findPreferredUpstreamType(ConnectivityManager cm,
TetheringConfiguration cfg) {
int upType = ConnectivityManager.TYPE_NONE; int upType = ConnectivityManager.TYPE_NONE;
updateConfiguration(); // TODO - remove?
final TetheringConfiguration cfg = mConfig;
if (VDBG) { if (VDBG) {
Log.d(TAG, "chooseUpstreamType has upstream iface types:"); Log.d(TAG, "chooseUpstreamType has upstream iface types:");
for (Integer netType : cfg.preferredUpstreamIfaceTypes) { for (Integer netType : cfg.preferredUpstreamIfaceTypes) {
@@ -1267,27 +1270,18 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering
final int preferredUpstreamMobileApn = cfg.isDunRequired final int preferredUpstreamMobileApn = cfg.isDunRequired
? ConnectivityManager.TYPE_MOBILE_DUN ? ConnectivityManager.TYPE_MOBILE_DUN
: ConnectivityManager.TYPE_MOBILE_HIPRI; : ConnectivityManager.TYPE_MOBILE_HIPRI;
if (DBG) { mLog.log(String.format(
Log.d(TAG, "chooseUpstreamType(" + tryCell + ")," "findPreferredUpstreamType(), preferredApn=%s, got type=%s",
+ " preferredApn=" getNetworkTypeName(preferredUpstreamMobileApn),
+ ConnectivityManager.getNetworkTypeName(preferredUpstreamMobileApn) getNetworkTypeName(upType)));
+ ", got type="
+ ConnectivityManager.getNetworkTypeName(upType));
}
switch (upType) { switch (upType) {
case ConnectivityManager.TYPE_MOBILE_DUN: case ConnectivityManager.TYPE_MOBILE_DUN:
case ConnectivityManager.TYPE_MOBILE_HIPRI: case ConnectivityManager.TYPE_MOBILE_HIPRI:
// If we're on DUN, put our own grab on it. // If we're on DUN, put our own grab on it.
requestUpstreamMobileConnection(); mUpstreamNetworkMonitor.registerMobileNetworkRequest();
break; break;
case ConnectivityManager.TYPE_NONE: case ConnectivityManager.TYPE_NONE:
if (tryCell) {
requestUpstreamMobileConnection();
// We think mobile should be coming up; don't set a retry.
} else {
sendMessageDelayed(CMD_RETRY_UPSTREAM, UPSTREAM_SETTLE_TIME_MS);
}
break; break;
default: default:
/* If we've found an active upstream connection that's not DUN/HIPRI /* If we've found an active upstream connection that's not DUN/HIPRI
@@ -1296,7 +1290,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering
* If we found NONE we don't want to do this as we want any previous * If we found NONE we don't want to do this as we want any previous
* requests to keep trying to bring up something we can use. * requests to keep trying to bring up something we can use.
*/ */
unrequestUpstreamMobileConnection(); mUpstreamNetworkMonitor.releaseMobileNetworkRequest();
break; break;
} }
@@ -1455,7 +1449,6 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering
@Override @Override
public void exit() { public void exit() {
mOffloadController.stop(); mOffloadController.stop();
unrequestUpstreamMobileConnection();
mUpstreamNetworkMonitor.stop(); mUpstreamNetworkMonitor.stop();
mSimChange.stopListening(); mSimChange.stopListening();
notifyTetheredOfNewUpstreamIface(null); notifyTetheredOfNewUpstreamIface(null);

View File

@@ -332,19 +332,16 @@ public class UpstreamNetworkMonitor {
@Override @Override
public void onAvailable(Network network) { public void onAvailable(Network network) {
checkExpectedThread();
handleAvailable(mCallbackType, network); handleAvailable(mCallbackType, network);
} }
@Override @Override
public void onCapabilitiesChanged(Network network, NetworkCapabilities newNc) { public void onCapabilitiesChanged(Network network, NetworkCapabilities newNc) {
checkExpectedThread();
handleNetCap(network, newNc); handleNetCap(network, newNc);
} }
@Override @Override
public void onLinkPropertiesChanged(Network network, LinkProperties newLp) { public void onLinkPropertiesChanged(Network network, LinkProperties newLp) {
checkExpectedThread();
handleLinkProp(network, newLp); handleLinkProp(network, newLp);
} }
@@ -353,15 +350,8 @@ public class UpstreamNetworkMonitor {
@Override @Override
public void onLost(Network network) { public void onLost(Network network) {
checkExpectedThread();
handleLost(mCallbackType, network); handleLost(mCallbackType, network);
} }
private void checkExpectedThread() {
if (Looper.myLooper() != mHandler.getLooper()) {
Log.wtf(TAG, "Handling callback in unexpected thread.");
}
}
} }
private void releaseCallback(NetworkCallback cb) { private void releaseCallback(NetworkCallback cb) {