public int setUsbTethering(boolean enable) {
if (VDBG) Log.d(TAG, "setUsbTethering(" + enable + ")");
UsbManager usbManager = mContext.getSystemService(UsbManager.class);
- if (usbManager == null) {
- return enable ? ConnectivityManager.TETHER_ERROR_MASTER_ERROR
- : ConnectivityManager.TETHER_ERROR_NO_ERROR;
- }
synchronized (mPublicSync) {
if (enable) {
private final ArrayList<TetherInterfaceStateMachine> mNotifyList;
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;
return false;
}
- protected boolean turnOnUpstreamMobileConnection(int apnType) {
+ protected boolean requestUpstreamMobileConnection(int apnType) {
if (apnType == ConnectivityManager.TYPE_NONE) { return false; }
- if (apnType != mPreviousMobileApn) {
+ if (apnType != mPreviousMobileType) {
// Unregister any previous mobile upstream callback because
// this request, if any, will be different.
- turnOffUpstreamMobileConnection();
+ unrequestUpstreamMobileConnection();
}
if (mUpstreamNetworkMonitor.mobileNetworkRequested()) {
case ConnectivityManager.TYPE_MOBILE_DUN:
case ConnectivityManager.TYPE_MOBILE:
case ConnectivityManager.TYPE_MOBILE_HIPRI:
- mPreviousMobileApn = apnType;
+ mPreviousMobileType = apnType;
break;
default:
return false;
}
- // TODO: This should be called by the code that observes
- // configuration changes, once the above code in this function
- // is simplified (i.e. eradicated).
- mUpstreamNetworkMonitor.mobileUpstreamRequiresDun(
+ // TODO: Replace this with a call to pass the current tethering
+ // configuration to mUpstreamNetworkMonitor and let it handle
+ // choosing APN type accordingly.
+ mUpstreamNetworkMonitor.updateMobileRequiresDun(
apnType == ConnectivityManager.TYPE_MOBILE_DUN);
mUpstreamNetworkMonitor.registerMobileNetworkRequest();
return true;
}
- protected void turnOffUpstreamMobileConnection() {
+ protected void unrequestUpstreamMobileConnection() {
mUpstreamNetworkMonitor.releaseMobileNetworkRequest();
- mPreviousMobileApn = ConnectivityManager.TYPE_NONE;
+ mPreviousMobileType = ConnectivityManager.TYPE_NONE;
}
protected boolean turnOnMasterTetherSettings() {
case ConnectivityManager.TYPE_MOBILE_DUN:
case ConnectivityManager.TYPE_MOBILE_HIPRI:
// If we're on DUN, put our own grab on it.
- turnOnUpstreamMobileConnection(upType);
+ requestUpstreamMobileConnection(upType);
break;
case ConnectivityManager.TYPE_NONE:
if (tryCell &&
- turnOnUpstreamMobileConnection(mPreferredUpstreamMobileApn)) {
+ requestUpstreamMobileConnection(mPreferredUpstreamMobileApn)) {
// We think mobile should be coming up; don't set a retry.
} else {
sendMessageDelayed(CMD_RETRY_UPSTREAM, UPSTREAM_SETTLE_TIME_MS);
* 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.
*/
- turnOffUpstreamMobileConnection();
+ unrequestUpstreamMobileConnection();
break;
}
@Override
public void exit() {
- turnOffUpstreamMobileConnection();
+ unrequestUpstreamMobileConnection();
mUpstreamNetworkMonitor.stop();
stopListeningForSimChanges();
notifyTetheredOfNewUpstreamIface(null);
mNetworkMap.clear();
}
- public void mobileUpstreamRequiresDun(boolean dunRequired) {
+ public void updateMobileRequiresDun(boolean dunRequired) {
final boolean valueChanged = (mDunRequired != dunRequired);
mDunRequired = dunRequired;
if (valueChanged && mobileNetworkRequested()) {
}
public void registerMobileNetworkRequest() {
- if (mMobileNetworkCallback != null) return;
+ if (mMobileNetworkCallback != null) {
+ Log.e(TAG, "registerMobileNetworkRequest() already registered");
+ return;
+ }
final NetworkRequest.Builder builder = new NetworkRequest.Builder()
.addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR);
// Therefore, to avoid duplicate notifications, we only register a no-op.
mMobileNetworkCallback = new NetworkCallback();
- // TODO: Change the timeout from 0 (no onUnavailable callback) to use some
- // moderate callback time (once timeout callbacks are implemented). This might
- // be useful for updating some UI. Additionally, we should definitely log a
- // message to aid in any subsequent debugging
- if (DBG) Log.d(TAG, "requesting mobile upstream network: " + mobileUpstreamRequest);
+ // TODO: Change the timeout from 0 (no onUnavailable callback) to some
+ // moderate callback timeout. This might be useful for updating some UI.
+ // Additionally, we log a message to aid in any subsequent debugging.
+ Log.d(TAG, "requesting mobile upstream network: " + mobileUpstreamRequest);
// The following use of the legacy type system cannot be removed until
// after upstream selection no longer finds networks by legacy type.
assertFalse(unm.mobileNetworkRequested());
// Given a null Context, and therefore a null ConnectivityManager,
// these would cause an exception, if they actually attempted anything.
- unm.mobileUpstreamRequiresDun(true);
- unm.mobileUpstreamRequiresDun(false);
+ unm.updateMobileRequiresDun(true);
+ unm.updateMobileRequiresDun(false);
}
@Test
assertFalse(mUNM.mobileNetworkRequested());
assertEquals(0, mCM.requested.size());
- mUNM.mobileUpstreamRequiresDun(false);
+ mUNM.updateMobileRequiresDun(false);
assertFalse(mUNM.mobileNetworkRequested());
assertEquals(0, mCM.requested.size());
assertFalse(mUNM.mobileNetworkRequested());
assertEquals(0, mCM.requested.size());
- mUNM.mobileUpstreamRequiresDun(true);
+ mUNM.updateMobileRequiresDun(true);
assertFalse(mUNM.mobileNetworkRequested());
assertEquals(0, mCM.requested.size());