Integrate testNetworkService and Manager with Connectivity stack
This change adds TestAPIs for tests to retrive an instance of ConnectivityManager, allowing it to build test TUN interfaces, as well as test networks. This also integrates the TestNetwork types with ConnectivityManager, creating virtual networks if the network agent is a test agent. Bug: 72950854 Test: Compiles, CTS tests using this passing correctly Change-Id: I741ef9cdf4bd4125d9129af3a030edf32f438e4f
This commit is contained in:
@@ -219,4 +219,6 @@ interface IConnectivityManager
|
||||
|
||||
void registerTetheringEventCallback(ITetheringEventCallback callback, String callerPkg);
|
||||
void unregisterTetheringEventCallback(ITetheringEventCallback callback, String callerPkg);
|
||||
|
||||
IBinder startOrGetTestNetworkService();
|
||||
}
|
||||
|
||||
@@ -299,6 +299,15 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
private INetworkPolicyManager mPolicyManager;
|
||||
private NetworkPolicyManagerInternal mPolicyManagerInternal;
|
||||
|
||||
/**
|
||||
* TestNetworkService (lazily) created upon first usage. Locked to prevent creation of multiple
|
||||
* instances.
|
||||
*/
|
||||
@GuardedBy("mTNSLock")
|
||||
private TestNetworkService mTNS;
|
||||
|
||||
private final Object mTNSLock = new Object();
|
||||
|
||||
private String mCurrentTcpBufferSizes;
|
||||
|
||||
private static final SparseArray<String> sMagicDecoderRing = MessageUtils.findMessageNames(
|
||||
@@ -6958,4 +6967,22 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
return vpn != null && vpn.getLockdown();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a IBinder to a TestNetworkService. Will be lazily created as needed.
|
||||
*
|
||||
* <p>The TestNetworkService must be run in the system server due to TUN creation.
|
||||
*/
|
||||
@Override
|
||||
public IBinder startOrGetTestNetworkService() {
|
||||
synchronized (mTNSLock) {
|
||||
TestNetworkService.enforceTestNetworkPermissions(mContext);
|
||||
|
||||
if (mTNS == null) {
|
||||
mTNS = new TestNetworkService(mContext, mNMS);
|
||||
}
|
||||
|
||||
return mTNS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user