Make Tethering file NetworkRequests only if needed.
Currently, Tethering files NetworkRequests even when config_tether_upstream_automatic is enabled. This is incorrect: when the automatic upstream selection is enabled, the tethering upstream should always follow the default network and there is no need to file any requests. These requests are harmful when tethering is not using cellular as its upstream, because: - If the device does not use mobile data always on, the request causes the cellular network to be brought up, causing power draw. - Even if the device does use mobile data always on, the request causes the cellular network to come to the foreground, which allows all apps to access it, causing potential data usage. Amend the existing testGetCurrentPreferredUpstream to cover these changes, by making that test case always set automatic upstream mode. This does not result in any loss of meaningful test coverage, because getCurrentPreferredUpstream is only ever called when chooseUpstreamAutomatically is enabled. Bug: 173068192 Test: atest TetheringTests Change-Id: I068a5338699a3ed04f24f97f785ea89ff5890e50
This commit is contained in:
@@ -199,17 +199,22 @@ public class UpstreamNetworkMonitor {
|
||||
|
||||
private void reevaluateUpstreamRequirements(boolean tryCell, boolean autoUpstream,
|
||||
boolean dunRequired) {
|
||||
final boolean mobileRequestWasRequired = mTryCell && (mDunRequired || !mAutoUpstream);
|
||||
final boolean mobileRequestIsRequired = tryCell && (dunRequired || !autoUpstream);
|
||||
final boolean mobileRequestRequired = tryCell && (dunRequired || !autoUpstream);
|
||||
final boolean dunRequiredChanged = (mDunRequired != dunRequired);
|
||||
|
||||
mTryCell = tryCell;
|
||||
mDunRequired = dunRequired;
|
||||
mAutoUpstream = autoUpstream;
|
||||
|
||||
if (dunRequiredChanged && mobileNetworkRequested()) {
|
||||
releaseMobileNetworkRequest();
|
||||
if (mobileRequestRequired && !mobileNetworkRequested()) {
|
||||
registerMobileNetworkRequest();
|
||||
} else if (mobileNetworkRequested() && !mobileRequestRequired) {
|
||||
releaseMobileNetworkRequest();
|
||||
} else if (mobileNetworkRequested() && dunRequiredChanged) {
|
||||
releaseMobileNetworkRequest();
|
||||
if (mobileRequestRequired) {
|
||||
registerMobileNetworkRequest();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,11 +226,6 @@ public class UpstreamNetworkMonitor {
|
||||
*/
|
||||
public void setTryCell(boolean tryCell) {
|
||||
reevaluateUpstreamRequirements(tryCell, mAutoUpstream, mDunRequired);
|
||||
if (tryCell) {
|
||||
registerMobileNetworkRequest();
|
||||
} else {
|
||||
releaseMobileNetworkRequest();
|
||||
}
|
||||
}
|
||||
|
||||
/** Informs UpstreamNetworkMonitor of upstream configuration parameters. */
|
||||
@@ -274,7 +274,9 @@ public class UpstreamNetworkMonitor {
|
||||
// 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.
|
||||
mLog.i("requesting mobile upstream network: " + mobileUpstreamRequest);
|
||||
mLog.i("requesting mobile upstream network: " + mobileUpstreamRequest
|
||||
+ " mTryCell=" + mTryCell + " mAutoUpstream=" + mAutoUpstream
|
||||
+ " mDunRequired=" + mDunRequired);
|
||||
|
||||
cm().requestNetwork(mobileUpstreamRequest, 0, legacyType, mHandler,
|
||||
mMobileNetworkCallback);
|
||||
|
||||
Reference in New Issue
Block a user