Merge "Integrate testNetworkService and Manager with Connectivity stack"

This commit is contained in:
Benedict Wong
2019-03-15 17:41:02 +00:00
committed by Gerrit Code Review
2 changed files with 29 additions and 0 deletions

View File

@@ -220,4 +220,6 @@ interface IConnectivityManager
void registerTetheringEventCallback(ITetheringEventCallback callback, String callerPkg);
void unregisterTetheringEventCallback(ITetheringEventCallback callback, String callerPkg);
IBinder startOrGetTestNetworkService();
}

View File

@@ -300,6 +300,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(
@@ -6959,4 +6968,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;
}
}
}