Merge "Address comments from previous change (320592)" am: e7cb6c3761 am: b6f606b59f
am: 454a408717
Change-Id: I374c8c63e4fb3310c3c50cc531a65005991c2fe2
This commit is contained in:
@@ -911,10 +911,6 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering
|
|||||||
public int setUsbTethering(boolean enable) {
|
public int setUsbTethering(boolean enable) {
|
||||||
if (VDBG) Log.d(TAG, "setUsbTethering(" + enable + ")");
|
if (VDBG) Log.d(TAG, "setUsbTethering(" + enable + ")");
|
||||||
UsbManager usbManager = mContext.getSystemService(UsbManager.class);
|
UsbManager usbManager = mContext.getSystemService(UsbManager.class);
|
||||||
if (usbManager == null) {
|
|
||||||
return enable ? ConnectivityManager.TETHER_ERROR_MASTER_ERROR
|
|
||||||
: ConnectivityManager.TETHER_ERROR_NO_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized (mPublicSync) {
|
synchronized (mPublicSync) {
|
||||||
if (enable) {
|
if (enable) {
|
||||||
@@ -1103,7 +1099,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering
|
|||||||
private final ArrayList<TetherInterfaceStateMachine> mNotifyList;
|
private final ArrayList<TetherInterfaceStateMachine> mNotifyList;
|
||||||
private final IPv6TetheringCoordinator mIPv6TetheringCoordinator;
|
private final IPv6TetheringCoordinator mIPv6TetheringCoordinator;
|
||||||
|
|
||||||
private int mPreviousMobileApn = ConnectivityManager.TYPE_NONE;
|
private int mPreviousMobileType = ConnectivityManager.TYPE_NONE;
|
||||||
|
|
||||||
private static final int UPSTREAM_SETTLE_TIME_MS = 10000;
|
private static final int UPSTREAM_SETTLE_TIME_MS = 10000;
|
||||||
|
|
||||||
@@ -1138,13 +1134,13 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean turnOnUpstreamMobileConnection(int apnType) {
|
protected boolean requestUpstreamMobileConnection(int apnType) {
|
||||||
if (apnType == ConnectivityManager.TYPE_NONE) { return false; }
|
if (apnType == ConnectivityManager.TYPE_NONE) { return false; }
|
||||||
|
|
||||||
if (apnType != mPreviousMobileApn) {
|
if (apnType != mPreviousMobileType) {
|
||||||
// Unregister any previous mobile upstream callback because
|
// Unregister any previous mobile upstream callback because
|
||||||
// this request, if any, will be different.
|
// this request, if any, will be different.
|
||||||
turnOffUpstreamMobileConnection();
|
unrequestUpstreamMobileConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mUpstreamNetworkMonitor.mobileNetworkRequested()) {
|
if (mUpstreamNetworkMonitor.mobileNetworkRequested()) {
|
||||||
@@ -1156,25 +1152,25 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering
|
|||||||
case ConnectivityManager.TYPE_MOBILE_DUN:
|
case ConnectivityManager.TYPE_MOBILE_DUN:
|
||||||
case ConnectivityManager.TYPE_MOBILE:
|
case ConnectivityManager.TYPE_MOBILE:
|
||||||
case ConnectivityManager.TYPE_MOBILE_HIPRI:
|
case ConnectivityManager.TYPE_MOBILE_HIPRI:
|
||||||
mPreviousMobileApn = apnType;
|
mPreviousMobileType = apnType;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: This should be called by the code that observes
|
// TODO: Replace this with a call to pass the current tethering
|
||||||
// configuration changes, once the above code in this function
|
// configuration to mUpstreamNetworkMonitor and let it handle
|
||||||
// is simplified (i.e. eradicated).
|
// choosing APN type accordingly.
|
||||||
mUpstreamNetworkMonitor.mobileUpstreamRequiresDun(
|
mUpstreamNetworkMonitor.updateMobileRequiresDun(
|
||||||
apnType == ConnectivityManager.TYPE_MOBILE_DUN);
|
apnType == ConnectivityManager.TYPE_MOBILE_DUN);
|
||||||
|
|
||||||
mUpstreamNetworkMonitor.registerMobileNetworkRequest();
|
mUpstreamNetworkMonitor.registerMobileNetworkRequest();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void turnOffUpstreamMobileConnection() {
|
protected void unrequestUpstreamMobileConnection() {
|
||||||
mUpstreamNetworkMonitor.releaseMobileNetworkRequest();
|
mUpstreamNetworkMonitor.releaseMobileNetworkRequest();
|
||||||
mPreviousMobileApn = ConnectivityManager.TYPE_NONE;
|
mPreviousMobileType = ConnectivityManager.TYPE_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean turnOnMasterTetherSettings() {
|
protected boolean turnOnMasterTetherSettings() {
|
||||||
@@ -1253,11 +1249,11 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering
|
|||||||
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.
|
||||||
turnOnUpstreamMobileConnection(upType);
|
requestUpstreamMobileConnection(upType);
|
||||||
break;
|
break;
|
||||||
case ConnectivityManager.TYPE_NONE:
|
case ConnectivityManager.TYPE_NONE:
|
||||||
if (tryCell &&
|
if (tryCell &&
|
||||||
turnOnUpstreamMobileConnection(mPreferredUpstreamMobileApn)) {
|
requestUpstreamMobileConnection(mPreferredUpstreamMobileApn)) {
|
||||||
// We think mobile should be coming up; don't set a retry.
|
// We think mobile should be coming up; don't set a retry.
|
||||||
} else {
|
} else {
|
||||||
sendMessageDelayed(CMD_RETRY_UPSTREAM, UPSTREAM_SETTLE_TIME_MS);
|
sendMessageDelayed(CMD_RETRY_UPSTREAM, UPSTREAM_SETTLE_TIME_MS);
|
||||||
@@ -1270,7 +1266,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.
|
||||||
*/
|
*/
|
||||||
turnOffUpstreamMobileConnection();
|
unrequestUpstreamMobileConnection();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1491,7 +1487,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void exit() {
|
public void exit() {
|
||||||
turnOffUpstreamMobileConnection();
|
unrequestUpstreamMobileConnection();
|
||||||
mUpstreamNetworkMonitor.stop();
|
mUpstreamNetworkMonitor.stop();
|
||||||
stopListeningForSimChanges();
|
stopListeningForSimChanges();
|
||||||
notifyTetheredOfNewUpstreamIface(null);
|
notifyTetheredOfNewUpstreamIface(null);
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ public class UpstreamNetworkMonitor {
|
|||||||
mNetworkMap.clear();
|
mNetworkMap.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void mobileUpstreamRequiresDun(boolean dunRequired) {
|
public void updateMobileRequiresDun(boolean dunRequired) {
|
||||||
final boolean valueChanged = (mDunRequired != dunRequired);
|
final boolean valueChanged = (mDunRequired != dunRequired);
|
||||||
mDunRequired = dunRequired;
|
mDunRequired = dunRequired;
|
||||||
if (valueChanged && mobileNetworkRequested()) {
|
if (valueChanged && mobileNetworkRequested()) {
|
||||||
@@ -123,7 +123,10 @@ public class UpstreamNetworkMonitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void registerMobileNetworkRequest() {
|
public void registerMobileNetworkRequest() {
|
||||||
if (mMobileNetworkCallback != null) return;
|
if (mMobileNetworkCallback != null) {
|
||||||
|
Log.e(TAG, "registerMobileNetworkRequest() already registered");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
final NetworkRequest.Builder builder = new NetworkRequest.Builder()
|
final NetworkRequest.Builder builder = new NetworkRequest.Builder()
|
||||||
.addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR);
|
.addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR);
|
||||||
@@ -139,11 +142,10 @@ public class UpstreamNetworkMonitor {
|
|||||||
// Therefore, to avoid duplicate notifications, we only register a no-op.
|
// Therefore, to avoid duplicate notifications, we only register a no-op.
|
||||||
mMobileNetworkCallback = new NetworkCallback();
|
mMobileNetworkCallback = new NetworkCallback();
|
||||||
|
|
||||||
// TODO: Change the timeout from 0 (no onUnavailable callback) to use some
|
// TODO: Change the timeout from 0 (no onUnavailable callback) to some
|
||||||
// moderate callback time (once timeout callbacks are implemented). This might
|
// moderate callback timeout. This might be useful for updating some UI.
|
||||||
// be useful for updating some UI. Additionally, we should definitely log a
|
// Additionally, we log a message to aid in any subsequent debugging.
|
||||||
// message to aid in any subsequent debugging
|
Log.d(TAG, "requesting mobile upstream network: " + mobileUpstreamRequest);
|
||||||
if (DBG) Log.d(TAG, "requesting mobile upstream network: " + mobileUpstreamRequest);
|
|
||||||
|
|
||||||
// The following use of the legacy type system cannot be removed until
|
// The following use of the legacy type system cannot be removed until
|
||||||
// after upstream selection no longer finds networks by legacy type.
|
// after upstream selection no longer finds networks by legacy type.
|
||||||
|
|||||||
@@ -73,8 +73,8 @@ public class UpstreamNetworkMonitorTest {
|
|||||||
assertFalse(unm.mobileNetworkRequested());
|
assertFalse(unm.mobileNetworkRequested());
|
||||||
// Given a null Context, and therefore a null ConnectivityManager,
|
// Given a null Context, and therefore a null ConnectivityManager,
|
||||||
// these would cause an exception, if they actually attempted anything.
|
// these would cause an exception, if they actually attempted anything.
|
||||||
unm.mobileUpstreamRequiresDun(true);
|
unm.updateMobileRequiresDun(true);
|
||||||
unm.mobileUpstreamRequiresDun(false);
|
unm.updateMobileRequiresDun(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -109,7 +109,7 @@ public class UpstreamNetworkMonitorTest {
|
|||||||
assertFalse(mUNM.mobileNetworkRequested());
|
assertFalse(mUNM.mobileNetworkRequested());
|
||||||
assertEquals(0, mCM.requested.size());
|
assertEquals(0, mCM.requested.size());
|
||||||
|
|
||||||
mUNM.mobileUpstreamRequiresDun(false);
|
mUNM.updateMobileRequiresDun(false);
|
||||||
assertFalse(mUNM.mobileNetworkRequested());
|
assertFalse(mUNM.mobileNetworkRequested());
|
||||||
assertEquals(0, mCM.requested.size());
|
assertEquals(0, mCM.requested.size());
|
||||||
|
|
||||||
@@ -135,7 +135,7 @@ public class UpstreamNetworkMonitorTest {
|
|||||||
assertFalse(mUNM.mobileNetworkRequested());
|
assertFalse(mUNM.mobileNetworkRequested());
|
||||||
assertEquals(0, mCM.requested.size());
|
assertEquals(0, mCM.requested.size());
|
||||||
|
|
||||||
mUNM.mobileUpstreamRequiresDun(true);
|
mUNM.updateMobileRequiresDun(true);
|
||||||
assertFalse(mUNM.mobileNetworkRequested());
|
assertFalse(mUNM.mobileNetworkRequested());
|
||||||
assertEquals(0, mCM.requested.size());
|
assertEquals(0, mCM.requested.size());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user