import android.net.IIpMemoryStore;
import android.net.IIpSecService;
import android.net.INetworkPolicyManager;
+import android.net.ITestNetworkManager;
import android.net.IpMemoryStore;
import android.net.IpSecManager;
import android.net.NetworkPolicyManager;
import android.net.NetworkScoreManager;
import android.net.NetworkWatchlistManager;
+import android.net.TestNetworkManager;
import android.net.lowpan.ILowpanManager;
import android.net.lowpan.LowpanManager;
import android.net.nsd.INsdManager;
import android.os.IncidentManager;
import android.os.PowerManager;
import android.os.RecoverySystem;
+import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.ServiceManager.ServiceNotFoundException;
import android.os.SystemUpdateManager;
return new IpSecManager(ctx, service);
}});
+ registerService(
+ Context.TEST_NETWORK_SERVICE,
+ TestNetworkManager.class,
+ new StaticApplicationContextServiceFetcher<TestNetworkManager>() {
+ @Override
+ public TestNetworkManager createService(Context context)
+ throws ServiceNotFoundException {
+ IBinder csBinder =
+ ServiceManager.getServiceOrThrow(Context.CONNECTIVITY_SERVICE);
+ IConnectivityManager csMgr =
+ IConnectivityManager.Stub.asInterface(csBinder);
+
+ final IBinder tnBinder;
+ try {
+ tnBinder = csMgr.startOrGetTestNetworkService();
+ } catch (RemoteException e) {
+ throw new ServiceNotFoundException(Context.TEST_NETWORK_SERVICE);
+ }
+ ITestNetworkManager tnMgr = ITestNetworkManager.Stub.asInterface(tnBinder);
+ return new TestNetworkManager(context, tnMgr);
+ }
+ });
+
registerService(Context.COUNTRY_DETECTOR, CountryDetector.class,
new StaticServiceFetcher<CountryDetector>() {
@Override
CONNECTIVITY_SERVICE,
//@hide: IP_MEMORY_STORE_SERVICE,
IPSEC_SERVICE,
+ TEST_NETWORK_SERVICE,
//@hide: UPDATE_LOCK_SERVICE,
//@hide: NETWORKMANAGEMENT_SERVICE,
NETWORK_STATS_SERVICE,
/**
* Use with {@link #getSystemService(String)} to retrieve a {@link
+ * android.net.TestNetworkManager} for building TUNs and limited-use Networks
+ *
+ * @see #getSystemService(String)
+ * @hide
+ */
+ @TestApi public static final String TEST_NETWORK_SERVICE = "test_network";
+
+ /**
+ * Use with {@link #getSystemService(String)} to retrieve a {@link
* android.os.IUpdateLock} for managing runtime sequences that
* must not be interrupted by headless OTA application or similar.
*
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(
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;
+ }
+ }
}