Merge "Add back compat config for NSD"
This commit is contained in:
22
TEST_MAPPING
22
TEST_MAPPING
@@ -35,6 +35,17 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
// CTS tests that target older SDKs.
|
// CTS tests that target older SDKs.
|
||||||
|
{
|
||||||
|
"name": "CtsNetTestCasesMaxTargetSdk30",
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"exclude-annotation": "com.android.testutils.SkipPresubmit"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"exclude-annotation": "androidx.test.filters.RequiresDevice"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "CtsNetTestCasesMaxTargetSdk31",
|
"name": "CtsNetTestCasesMaxTargetSdk31",
|
||||||
"options": [
|
"options": [
|
||||||
@@ -102,6 +113,17 @@
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "CtsNetTestCasesMaxTargetSdk30[CaptivePortalLoginGoogle.apk+NetworkStackGoogle.apk+com.google.android.resolv.apex+com.google.android.tethering.apex]",
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"exclude-annotation": "com.android.testutils.SkipPresubmit"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"exclude-annotation": "androidx.test.filters.RequiresDevice"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "CtsNetTestCasesMaxTargetSdk31[CaptivePortalLoginGoogle.apk+NetworkStackGoogle.apk+com.google.android.resolv.apex+com.google.android.tethering.apex]",
|
"name": "CtsNetTestCasesMaxTargetSdk31[CaptivePortalLoginGoogle.apk+NetworkStackGoogle.apk+com.google.android.resolv.apex+com.google.android.tethering.apex]",
|
||||||
"options": [
|
"options": [
|
||||||
|
|||||||
@@ -108,7 +108,10 @@ apex {
|
|||||||
|
|
||||||
androidManifest: "AndroidManifest.xml",
|
androidManifest: "AndroidManifest.xml",
|
||||||
|
|
||||||
compat_configs: ["connectivity-platform-compat-config"],
|
compat_configs: [
|
||||||
|
"connectivity-platform-compat-config",
|
||||||
|
"connectivity-t-platform-compat-config",
|
||||||
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
apex_key {
|
apex_key {
|
||||||
|
|||||||
@@ -142,3 +142,8 @@ java_sdk_library {
|
|||||||
"//packages/modules/Wifi/service/tests/wifitests",
|
"//packages/modules/Wifi/service/tests/wifitests",
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
platform_compat_config {
|
||||||
|
name: "connectivity-t-platform-compat-config",
|
||||||
|
src: ":framework-connectivity-t",
|
||||||
|
}
|
||||||
|
|||||||
@@ -139,17 +139,21 @@ public final class NsdManager {
|
|||||||
* The platform will only keep the daemon running as long as there are
|
* The platform will only keep the daemon running as long as there are
|
||||||
* any legacy apps connected.
|
* any legacy apps connected.
|
||||||
*
|
*
|
||||||
* After Android 12, directly communicate with native daemon might not
|
* After Android 12, direct communication with the native daemon might not work since the native
|
||||||
* work since the native damon won't always stay alive.
|
* daemon won't always stay alive. Using the NSD APIs from NsdManager as the replacement is
|
||||||
* Use the NSD APIs from NsdManager as the replacement is recommended.
|
* recommended.
|
||||||
* An another alternative could be bundling your own mdns solutions instead of
|
* Another alternative could be bundling your own mdns solutions instead of
|
||||||
* depending on the system mdns native daemon.
|
* depending on the system mdns native daemon.
|
||||||
*
|
*
|
||||||
|
* This compatibility change applies to Android 13 and later only. To toggle behavior on
|
||||||
|
* Android 12 and Android 12L, use RUN_NATIVE_NSD_ONLY_IF_LEGACY_APPS.
|
||||||
|
*
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
@ChangeId
|
@ChangeId
|
||||||
@EnabledSince(targetSdkVersion = android.os.Build.VERSION_CODES.S)
|
@EnabledSince(targetSdkVersion = android.os.Build.VERSION_CODES.S)
|
||||||
public static final long RUN_NATIVE_NSD_ONLY_IF_LEGACY_APPS = 191844585L;
|
// This was a platform change ID with value 191844585L before T
|
||||||
|
public static final long RUN_NATIVE_NSD_ONLY_IF_LEGACY_APPS_T_AND_LATER = 235355681L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Broadcast intent action to indicate whether network service discovery is
|
* Broadcast intent action to indicate whether network service discovery is
|
||||||
@@ -500,7 +504,7 @@ public final class NsdManager {
|
|||||||
|
|
||||||
// Only proactively start the daemon if the target SDK < S, otherwise the internal service
|
// Only proactively start the daemon if the target SDK < S, otherwise the internal service
|
||||||
// would automatically start/stop the native daemon as needed.
|
// would automatically start/stop the native daemon as needed.
|
||||||
if (!CompatChanges.isChangeEnabled(RUN_NATIVE_NSD_ONLY_IF_LEGACY_APPS)) {
|
if (!CompatChanges.isChangeEnabled(RUN_NATIVE_NSD_ONLY_IF_LEGACY_APPS_T_AND_LATER)) {
|
||||||
try {
|
try {
|
||||||
mService.startDaemon();
|
mService.startDaemon();
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
|
|||||||
@@ -128,3 +128,18 @@ android_test {
|
|||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
android_test {
|
||||||
|
name: "CtsNetTestCasesMaxTargetSdk30", // Must match CtsNetTestCasesMaxTargetSdk30 annotation.
|
||||||
|
defaults: [
|
||||||
|
"CtsNetTestCasesDefaults",
|
||||||
|
"CtsNetTestCasesApiStableDefaults",
|
||||||
|
],
|
||||||
|
target_sdk_version: "30",
|
||||||
|
package_name: "android.net.cts.maxtargetsdk30", // CTS package names must be unique.
|
||||||
|
instrumentation_target_package: "android.net.cts.maxtargetsdk30",
|
||||||
|
test_suites: [
|
||||||
|
"cts",
|
||||||
|
"general-tests",
|
||||||
|
"mts-networking",
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
package android.net.cts
|
package android.net.cts
|
||||||
|
|
||||||
import android.Manifest.permission.MANAGE_TEST_NETWORKS
|
import android.Manifest.permission.MANAGE_TEST_NETWORKS
|
||||||
|
import android.app.compat.CompatChanges
|
||||||
import android.net.ConnectivityManager
|
import android.net.ConnectivityManager
|
||||||
import android.net.ConnectivityManager.NetworkCallback
|
import android.net.ConnectivityManager.NetworkCallback
|
||||||
import android.net.LinkProperties
|
import android.net.LinkProperties
|
||||||
@@ -46,6 +47,7 @@ import android.net.nsd.NsdManager.DiscoveryListener
|
|||||||
import android.net.nsd.NsdManager.RegistrationListener
|
import android.net.nsd.NsdManager.RegistrationListener
|
||||||
import android.net.nsd.NsdManager.ResolveListener
|
import android.net.nsd.NsdManager.ResolveListener
|
||||||
import android.net.nsd.NsdServiceInfo
|
import android.net.nsd.NsdServiceInfo
|
||||||
|
import android.os.Build
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.HandlerThread
|
import android.os.HandlerThread
|
||||||
import android.os.Process.myTid
|
import android.os.Process.myTid
|
||||||
@@ -56,17 +58,23 @@ import androidx.test.runner.AndroidJUnit4
|
|||||||
import com.android.net.module.util.ArrayTrackRecord
|
import com.android.net.module.util.ArrayTrackRecord
|
||||||
import com.android.net.module.util.TrackRecord
|
import com.android.net.module.util.TrackRecord
|
||||||
import com.android.networkstack.apishim.NsdShimImpl
|
import com.android.networkstack.apishim.NsdShimImpl
|
||||||
|
import com.android.testutils.ConnectivityModuleTest
|
||||||
|
import com.android.testutils.DevSdkIgnoreRule
|
||||||
import com.android.testutils.TestableNetworkAgent
|
import com.android.testutils.TestableNetworkAgent
|
||||||
import com.android.testutils.TestableNetworkCallback
|
import com.android.testutils.TestableNetworkCallback
|
||||||
|
import com.android.testutils.filters.CtsNetTestCasesMaxTargetSdk30
|
||||||
import com.android.testutils.runAsShell
|
import com.android.testutils.runAsShell
|
||||||
import com.android.testutils.tryTest
|
import com.android.testutils.tryTest
|
||||||
import org.junit.After
|
import org.junit.After
|
||||||
import org.junit.Assert.assertArrayEquals
|
import org.junit.Assert.assertArrayEquals
|
||||||
|
import org.junit.Assert.assertFalse
|
||||||
import org.junit.Assert.assertTrue
|
import org.junit.Assert.assertTrue
|
||||||
import org.junit.Assume.assumeTrue
|
import org.junit.Assume.assumeTrue
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
|
import org.junit.Rule
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
|
import java.io.File
|
||||||
import java.net.ServerSocket
|
import java.net.ServerSocket
|
||||||
import java.nio.charset.StandardCharsets
|
import java.nio.charset.StandardCharsets
|
||||||
import java.util.Random
|
import java.util.Random
|
||||||
@@ -89,6 +97,10 @@ private val nsdShim = NsdShimImpl.newInstance()
|
|||||||
@AppModeFull(reason = "Socket cannot bind in instant app mode")
|
@AppModeFull(reason = "Socket cannot bind in instant app mode")
|
||||||
@RunWith(AndroidJUnit4::class)
|
@RunWith(AndroidJUnit4::class)
|
||||||
class NsdManagerTest {
|
class NsdManagerTest {
|
||||||
|
// Rule used to filter CtsNetTestCasesMaxTargetSdkXX
|
||||||
|
@get:Rule
|
||||||
|
val ignoreRule = DevSdkIgnoreRule()
|
||||||
|
|
||||||
private val context by lazy { InstrumentationRegistry.getInstrumentation().context }
|
private val context by lazy { InstrumentationRegistry.getInstrumentation().context }
|
||||||
private val nsdManager by lazy { context.getSystemService(NsdManager::class.java) }
|
private val nsdManager by lazy { context.getSystemService(NsdManager::class.java) }
|
||||||
|
|
||||||
@@ -692,6 +704,30 @@ class NsdManagerTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test @CtsNetTestCasesMaxTargetSdk30("Socket is started with the service up to target SDK 30")
|
||||||
|
fun testManagerCreatesLegacySocket() {
|
||||||
|
nsdManager // Ensure the lazy-init member is initialized, so NsdManager is created
|
||||||
|
val socket = File("/dev/socket/mdnsd")
|
||||||
|
val timeout = System.currentTimeMillis() + TIMEOUT_MS
|
||||||
|
while (!socket.exists() && System.currentTimeMillis() < timeout) {
|
||||||
|
Thread.sleep(10)
|
||||||
|
}
|
||||||
|
assertTrue("$socket was not found after $TIMEOUT_MS ms", socket.exists())
|
||||||
|
}
|
||||||
|
|
||||||
|
// The compat change is part of a connectivity module update that applies to T+
|
||||||
|
@ConnectivityModuleTest @DevSdkIgnoreRule.IgnoreUpTo(Build.VERSION_CODES.S_V2)
|
||||||
|
@Test @CtsNetTestCasesMaxTargetSdk30("Socket is started with the service up to target SDK 30")
|
||||||
|
fun testManagerCreatesLegacySocket_CompatChange() {
|
||||||
|
// The socket may have been already created by some other app, or some other test, in which
|
||||||
|
// case this test cannot verify creation. At least verify that the compat change is
|
||||||
|
// disabled in a process with max SDK 30; unit tests already verify that start is requested
|
||||||
|
// when the compat change is disabled.
|
||||||
|
// Note that before T the compat constant had a different int value.
|
||||||
|
assertFalse(CompatChanges.isChangeEnabled(
|
||||||
|
NsdManager.RUN_NATIVE_NSD_ONLY_IF_LEGACY_APPS_T_AND_LATER))
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a service and return its registration record.
|
* Register a service and return its registration record.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -81,70 +81,70 @@ public class NsdManagerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@EnableCompatChanges(NsdManager.RUN_NATIVE_NSD_ONLY_IF_LEGACY_APPS)
|
@EnableCompatChanges(NsdManager.RUN_NATIVE_NSD_ONLY_IF_LEGACY_APPS_T_AND_LATER)
|
||||||
public void testResolveServiceS() throws Exception {
|
public void testResolveServiceS() throws Exception {
|
||||||
verify(mServiceConn, never()).startDaemon();
|
verify(mServiceConn, never()).startDaemon();
|
||||||
doTestResolveService();
|
doTestResolveService();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisableCompatChanges(NsdManager.RUN_NATIVE_NSD_ONLY_IF_LEGACY_APPS)
|
@DisableCompatChanges(NsdManager.RUN_NATIVE_NSD_ONLY_IF_LEGACY_APPS_T_AND_LATER)
|
||||||
public void testResolveServicePreS() throws Exception {
|
public void testResolveServicePreS() throws Exception {
|
||||||
verify(mServiceConn).startDaemon();
|
verify(mServiceConn).startDaemon();
|
||||||
doTestResolveService();
|
doTestResolveService();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@EnableCompatChanges(NsdManager.RUN_NATIVE_NSD_ONLY_IF_LEGACY_APPS)
|
@EnableCompatChanges(NsdManager.RUN_NATIVE_NSD_ONLY_IF_LEGACY_APPS_T_AND_LATER)
|
||||||
public void testDiscoverServiceS() throws Exception {
|
public void testDiscoverServiceS() throws Exception {
|
||||||
verify(mServiceConn, never()).startDaemon();
|
verify(mServiceConn, never()).startDaemon();
|
||||||
doTestDiscoverService();
|
doTestDiscoverService();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisableCompatChanges(NsdManager.RUN_NATIVE_NSD_ONLY_IF_LEGACY_APPS)
|
@DisableCompatChanges(NsdManager.RUN_NATIVE_NSD_ONLY_IF_LEGACY_APPS_T_AND_LATER)
|
||||||
public void testDiscoverServicePreS() throws Exception {
|
public void testDiscoverServicePreS() throws Exception {
|
||||||
verify(mServiceConn).startDaemon();
|
verify(mServiceConn).startDaemon();
|
||||||
doTestDiscoverService();
|
doTestDiscoverService();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@EnableCompatChanges(NsdManager.RUN_NATIVE_NSD_ONLY_IF_LEGACY_APPS)
|
@EnableCompatChanges(NsdManager.RUN_NATIVE_NSD_ONLY_IF_LEGACY_APPS_T_AND_LATER)
|
||||||
public void testParallelResolveServiceS() throws Exception {
|
public void testParallelResolveServiceS() throws Exception {
|
||||||
verify(mServiceConn, never()).startDaemon();
|
verify(mServiceConn, never()).startDaemon();
|
||||||
doTestParallelResolveService();
|
doTestParallelResolveService();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisableCompatChanges(NsdManager.RUN_NATIVE_NSD_ONLY_IF_LEGACY_APPS)
|
@DisableCompatChanges(NsdManager.RUN_NATIVE_NSD_ONLY_IF_LEGACY_APPS_T_AND_LATER)
|
||||||
public void testParallelResolveServicePreS() throws Exception {
|
public void testParallelResolveServicePreS() throws Exception {
|
||||||
verify(mServiceConn).startDaemon();
|
verify(mServiceConn).startDaemon();
|
||||||
doTestParallelResolveService();
|
doTestParallelResolveService();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@EnableCompatChanges(NsdManager.RUN_NATIVE_NSD_ONLY_IF_LEGACY_APPS)
|
@EnableCompatChanges(NsdManager.RUN_NATIVE_NSD_ONLY_IF_LEGACY_APPS_T_AND_LATER)
|
||||||
public void testInvalidCallsS() throws Exception {
|
public void testInvalidCallsS() throws Exception {
|
||||||
verify(mServiceConn, never()).startDaemon();
|
verify(mServiceConn, never()).startDaemon();
|
||||||
doTestInvalidCalls();
|
doTestInvalidCalls();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisableCompatChanges(NsdManager.RUN_NATIVE_NSD_ONLY_IF_LEGACY_APPS)
|
@DisableCompatChanges(NsdManager.RUN_NATIVE_NSD_ONLY_IF_LEGACY_APPS_T_AND_LATER)
|
||||||
public void testInvalidCallsPreS() throws Exception {
|
public void testInvalidCallsPreS() throws Exception {
|
||||||
verify(mServiceConn).startDaemon();
|
verify(mServiceConn).startDaemon();
|
||||||
doTestInvalidCalls();
|
doTestInvalidCalls();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@EnableCompatChanges(NsdManager.RUN_NATIVE_NSD_ONLY_IF_LEGACY_APPS)
|
@EnableCompatChanges(NsdManager.RUN_NATIVE_NSD_ONLY_IF_LEGACY_APPS_T_AND_LATER)
|
||||||
public void testRegisterServiceS() throws Exception {
|
public void testRegisterServiceS() throws Exception {
|
||||||
verify(mServiceConn, never()).startDaemon();
|
verify(mServiceConn, never()).startDaemon();
|
||||||
doTestRegisterService();
|
doTestRegisterService();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisableCompatChanges(NsdManager.RUN_NATIVE_NSD_ONLY_IF_LEGACY_APPS)
|
@DisableCompatChanges(NsdManager.RUN_NATIVE_NSD_ONLY_IF_LEGACY_APPS_T_AND_LATER)
|
||||||
public void testRegisterServicePreS() throws Exception {
|
public void testRegisterServicePreS() throws Exception {
|
||||||
verify(mServiceConn).startDaemon();
|
verify(mServiceConn).startDaemon();
|
||||||
doTestRegisterService();
|
doTestRegisterService();
|
||||||
|
|||||||
@@ -159,7 +159,7 @@ public class NsdServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisableCompatChanges(NsdManager.RUN_NATIVE_NSD_ONLY_IF_LEGACY_APPS)
|
@DisableCompatChanges(NsdManager.RUN_NATIVE_NSD_ONLY_IF_LEGACY_APPS_T_AND_LATER)
|
||||||
public void testPreSClients() throws Exception {
|
public void testPreSClients() throws Exception {
|
||||||
// Pre S client connected, the daemon should be started.
|
// Pre S client connected, the daemon should be started.
|
||||||
connectClient(mService);
|
connectClient(mService);
|
||||||
@@ -186,7 +186,7 @@ public class NsdServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@EnableCompatChanges(NsdManager.RUN_NATIVE_NSD_ONLY_IF_LEGACY_APPS)
|
@EnableCompatChanges(NsdManager.RUN_NATIVE_NSD_ONLY_IF_LEGACY_APPS_T_AND_LATER)
|
||||||
public void testNoDaemonStartedWhenClientsConnect() throws Exception {
|
public void testNoDaemonStartedWhenClientsConnect() throws Exception {
|
||||||
// Creating an NsdManager will not cause daemon startup.
|
// Creating an NsdManager will not cause daemon startup.
|
||||||
connectClient(mService);
|
connectClient(mService);
|
||||||
@@ -220,7 +220,7 @@ public class NsdServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@EnableCompatChanges(NsdManager.RUN_NATIVE_NSD_ONLY_IF_LEGACY_APPS)
|
@EnableCompatChanges(NsdManager.RUN_NATIVE_NSD_ONLY_IF_LEGACY_APPS_T_AND_LATER)
|
||||||
public void testClientRequestsAreGCedAtDisconnection() throws Exception {
|
public void testClientRequestsAreGCedAtDisconnection() throws Exception {
|
||||||
final NsdManager client = connectClient(mService);
|
final NsdManager client = connectClient(mService);
|
||||||
final INsdManagerCallback cb1 = getCallback();
|
final INsdManagerCallback cb1 = getCallback();
|
||||||
@@ -263,7 +263,7 @@ public class NsdServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@EnableCompatChanges(NsdManager.RUN_NATIVE_NSD_ONLY_IF_LEGACY_APPS)
|
@EnableCompatChanges(NsdManager.RUN_NATIVE_NSD_ONLY_IF_LEGACY_APPS_T_AND_LATER)
|
||||||
public void testCleanupDelayNoRequestActive() throws Exception {
|
public void testCleanupDelayNoRequestActive() throws Exception {
|
||||||
final NsdManager client = connectClient(mService);
|
final NsdManager client = connectClient(mService);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user