Add a CompatChange flag to enable platform backend

Apps targeting sdk < U are considered to use a legacy native
daemon as NsdManager backend, but other apps use a
platform-integration mDNS implementation as backend. So add a
CompatChange flag to enable platform backend for non-legacy
apps.

Bug: 270306772
Test: atest FrameworksNetTests CtsNetTestCases
Change-Id: I7ba58f8a5186fb49ad5f8aeacc8b8234bef1eabe
This commit is contained in:
Paul Hu
2023-03-09 16:05:01 +08:00
parent d741db3334
commit 2e0a88c0fa
6 changed files with 108 additions and 24 deletions

View File

@@ -26,5 +26,5 @@ import android.os.Messenger;
* {@hide}
*/
interface INsdManager {
INsdServiceConnector connect(INsdManagerCallback cb);
INsdServiceConnector connect(INsdManagerCallback cb, boolean useJavaBackend);
}

View File

@@ -16,6 +16,7 @@
package android.net.nsd;
import static android.net.connectivity.ConnectivityCompatChanges.ENABLE_PLATFORM_MDNS_BACKEND;
import static android.net.connectivity.ConnectivityCompatChanges.RUN_NATIVE_NSD_ONLY_IF_LEGACY_APPS_T_AND_LATER;
import android.annotation.IntDef;
@@ -510,7 +511,8 @@ public final class NsdManager {
mHandler = new ServiceHandler(t.getLooper());
try {
mService = service.connect(new NsdCallbackImpl(mHandler));
mService = service.connect(new NsdCallbackImpl(mHandler), CompatChanges.isChangeEnabled(
ENABLE_PLATFORM_MDNS_BACKEND));
} catch (RemoteException e) {
throw new RuntimeException("Failed to connect to NsdService");
}