Merge "No-op Refactoring of startTrackDefaultNetwork"
This commit is contained in:
@@ -2040,8 +2040,7 @@ public class Tethering {
|
||||
}
|
||||
|
||||
private void startTrackDefaultNetwork() {
|
||||
mUpstreamNetworkMonitor.startTrackDefaultNetwork(mDeps.getDefaultNetworkRequest(),
|
||||
mEntitlementMgr);
|
||||
mUpstreamNetworkMonitor.startTrackDefaultNetwork(mEntitlementMgr);
|
||||
}
|
||||
|
||||
/** Get the latest value of the tethering entitlement check. */
|
||||
|
||||
@@ -20,7 +20,6 @@ import android.app.usage.NetworkStatsManager;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.content.Context;
|
||||
import android.net.INetd;
|
||||
import android.net.NetworkRequest;
|
||||
import android.net.ip.IpServer;
|
||||
import android.net.util.SharedLog;
|
||||
import android.os.Handler;
|
||||
@@ -98,11 +97,6 @@ public abstract class TetheringDependencies {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the NetworkRequest that should be fulfilled by the default network.
|
||||
*/
|
||||
public abstract NetworkRequest getDefaultNetworkRequest();
|
||||
|
||||
/**
|
||||
* Get a reference to the EntitlementManager to be used by tethering.
|
||||
*/
|
||||
|
||||
@@ -35,8 +35,6 @@ import android.net.IIntResultListener;
|
||||
import android.net.INetworkStackConnector;
|
||||
import android.net.ITetheringConnector;
|
||||
import android.net.ITetheringEventCallback;
|
||||
import android.net.NetworkCapabilities;
|
||||
import android.net.NetworkRequest;
|
||||
import android.net.NetworkStack;
|
||||
import android.net.TetheringRequestParcel;
|
||||
import android.net.dhcp.DhcpServerCallbacks;
|
||||
@@ -306,19 +304,6 @@ public class TetheringService extends Service {
|
||||
@VisibleForTesting
|
||||
public TetheringDependencies makeTetheringDependencies() {
|
||||
return new TetheringDependencies() {
|
||||
@Override
|
||||
public NetworkRequest getDefaultNetworkRequest() {
|
||||
// TODO: b/147280869, add a proper system API to replace this.
|
||||
final NetworkRequest trackDefaultRequest = new NetworkRequest.Builder()
|
||||
.clearCapabilities()
|
||||
.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED)
|
||||
.addCapability(NetworkCapabilities.NET_CAPABILITY_TRUSTED)
|
||||
.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_VPN)
|
||||
.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
|
||||
.build();
|
||||
return trackDefaultRequest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Looper getTetheringLooper() {
|
||||
final HandlerThread tetherThread = new HandlerThread("android.tethering");
|
||||
|
||||
@@ -47,6 +47,9 @@ import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.util.StateMachine;
|
||||
import com.android.networkstack.apishim.ConnectivityManagerShimImpl;
|
||||
import com.android.networkstack.apishim.common.ConnectivityManagerShim;
|
||||
import com.android.networkstack.apishim.common.UnsupportedApiLevelException;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@@ -142,33 +145,28 @@ public class UpstreamNetworkMonitor {
|
||||
mWhat = what;
|
||||
mLocalPrefixes = new HashSet<>();
|
||||
mIsDefaultCellularUpstream = false;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public UpstreamNetworkMonitor(
|
||||
ConnectivityManager cm, StateMachine tgt, SharedLog log, int what) {
|
||||
this((Context) null, tgt, log, what);
|
||||
mCM = cm;
|
||||
mCM = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tracking the system default network. This method should be called when system is ready.
|
||||
* Tracking the system default network. This method should be only called once when system is
|
||||
* ready, and the callback is never unregistered.
|
||||
*
|
||||
* @param defaultNetworkRequest should be the same as ConnectivityService default request
|
||||
* @param entitle a EntitlementManager object to communicate between EntitlementManager and
|
||||
* UpstreamNetworkMonitor
|
||||
*/
|
||||
public void startTrackDefaultNetwork(NetworkRequest defaultNetworkRequest,
|
||||
EntitlementManager entitle) {
|
||||
|
||||
// defaultNetworkRequest is not really a "request", just a way of tracking the system
|
||||
// default network. It's guaranteed not to actually bring up any networks because it's
|
||||
// the should be the same request as the ConnectivityService default request, and thus
|
||||
// shares fate with it. We can't use registerDefaultNetworkCallback because it will not
|
||||
// track the system default network if there is a VPN that applies to our UID.
|
||||
if (mDefaultNetworkCallback == null) {
|
||||
mDefaultNetworkCallback = new UpstreamNetworkCallback(CALLBACK_DEFAULT_INTERNET);
|
||||
cm().requestNetwork(defaultNetworkRequest, mDefaultNetworkCallback, mHandler);
|
||||
public void startTrackDefaultNetwork(EntitlementManager entitle) {
|
||||
if (mDefaultNetworkCallback != null) {
|
||||
Log.wtf(TAG, "default network callback is already registered");
|
||||
return;
|
||||
}
|
||||
ConnectivityManagerShim mCmShim = ConnectivityManagerShimImpl.newInstance(mContext);
|
||||
mDefaultNetworkCallback = new UpstreamNetworkCallback(CALLBACK_DEFAULT_INTERNET);
|
||||
try {
|
||||
mCmShim.registerSystemDefaultNetworkCallback(mDefaultNetworkCallback, mHandler);
|
||||
} catch (UnsupportedApiLevelException e) {
|
||||
Log.wtf(TAG, "registerSystemDefaultNetworkCallback is not supported");
|
||||
return;
|
||||
}
|
||||
if (mEntitlementMgr == null) {
|
||||
mEntitlementMgr = entitle;
|
||||
|
||||
Reference in New Issue
Block a user