Remove NsdShim as it is not required
NsdShim is added to make the NsdManagerTest buildable in some old
branch. As a part of migrating to new branch, the nsdShim is not
needed anymore.
Test: atest CtsNetTestCases:android.net.cts.NsdManagerTest
Change-Id: Ie04fca274738d0d2262c2b801338c797894cb443
diff --git a/apishim/29/com/android/networkstack/apishim/api29/NsdShimImpl.java b/apishim/29/com/android/networkstack/apishim/api29/NsdShimImpl.java
deleted file mode 100644
index ac0c69a..0000000
--- a/apishim/29/com/android/networkstack/apishim/api29/NsdShimImpl.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Copyright (C) 2022 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.networkstack.apishim.api29;
-
-import android.net.Network;
-import android.net.NetworkRequest;
-import android.net.nsd.NsdManager;
-import android.net.nsd.NsdServiceInfo;
-import android.os.Build;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-import androidx.annotation.RequiresApi;
-
-import com.android.networkstack.apishim.common.NsdShim;
-import com.android.networkstack.apishim.common.UnsupportedApiLevelException;
-
-import java.util.concurrent.Executor;
-
-/**
- * Implementation of {@link NsdShim}.
- */
-@RequiresApi(Build.VERSION_CODES.Q)
-public class NsdShimImpl implements NsdShim {
-
- /**
- * Get a new instance of {@link NsdShim}.
- */
- public static NsdShim newInstance() {
- return new NsdShimImpl();
- }
-
- @Nullable
- @Override
- public Network getNetwork(@NonNull NsdServiceInfo serviceInfo) {
- // NsdServiceInfo has no Network before T
- return null;
- }
-
- @Override
- public void setNetwork(@NonNull NsdServiceInfo serviceInfo, @Nullable Network network) {
- // No-op: NsdServiceInfo has no Network before T
- }
-
- @Override
- public void registerService(@NonNull NsdManager nsdManager, @NonNull NsdServiceInfo serviceInfo,
- int protocolType, @NonNull Executor executor,
- @NonNull NsdManager.RegistrationListener listener) throws UnsupportedApiLevelException {
- throw new UnsupportedApiLevelException("Register with an executor is only supported on T+");
- }
-
- @Override
- public void discoverServices(@NonNull NsdManager nsdManager, @NonNull String serviceType,
- int protocolType, @Nullable Network network,
- @NonNull Executor executor, @NonNull NsdManager.DiscoveryListener listener)
- throws UnsupportedApiLevelException {
- throw new UnsupportedApiLevelException("Discover on network is only supported on T+");
- }
-
- @Override
- public void discoverServices(@NonNull NsdManager nsdManager, @NonNull String serviceType,
- int protocolType, @Nullable NetworkRequest request,
- @NonNull Executor executor, @NonNull NsdManager.DiscoveryListener listener)
- throws UnsupportedApiLevelException {
- throw new UnsupportedApiLevelException(
- "Discover with NetworkRequest is only supported on T+");
- }
-
- @Override
- public void resolveService(@NonNull NsdManager nsdManager, @NonNull NsdServiceInfo serviceInfo,
- @NonNull Executor executor, @NonNull NsdManager.ResolveListener resolveListener)
- throws UnsupportedApiLevelException {
- throw new UnsupportedApiLevelException("Resolve with executor is only supported on T+");
- }
-
- @Override
- public void stopServiceResolution(@NonNull NsdManager nsdManager,
- @NonNull NsdManager.ResolveListener resolveListener)
- throws UnsupportedApiLevelException {
- throw new UnsupportedApiLevelException("Stop service resolution is only supported on U+");
- }
-}
diff --git a/apishim/31/com/android/networkstack/apishim/api31/NsdShimImpl.java b/apishim/31/com/android/networkstack/apishim/api31/NsdShimImpl.java
deleted file mode 100644
index 0e89b59..0000000
--- a/apishim/31/com/android/networkstack/apishim/api31/NsdShimImpl.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Copyright (C) 2022 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.networkstack.apishim.api31;
-
-/**
- * Implementation of {@link com.android.networkstack.apishim.common.NsdShim}.
- */
-public class NsdShimImpl extends com.android.networkstack.apishim.api29.NsdShimImpl {
- // Inherit everything from API29 shim
-}
diff --git a/apishim/33/com/android/networkstack/apishim/api33/NsdShimImpl.java b/apishim/33/com/android/networkstack/apishim/api33/NsdShimImpl.java
deleted file mode 100644
index 1f0907f..0000000
--- a/apishim/33/com/android/networkstack/apishim/api33/NsdShimImpl.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Copyright (C) 2022 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.networkstack.apishim.api33;
-
-import android.net.Network;
-import android.net.NetworkRequest;
-import android.net.nsd.NsdManager;
-import android.net.nsd.NsdServiceInfo;
-import android.os.Build;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-import androidx.annotation.RequiresApi;
-
-import com.android.modules.utils.build.SdkLevel;
-import com.android.networkstack.apishim.common.NsdShim;
-import com.android.networkstack.apishim.common.UnsupportedApiLevelException;
-
-import java.util.concurrent.Executor;
-
-/**
- * Implementation of {@link com.android.networkstack.apishim.common.NsdShim}.
- */
-@RequiresApi(Build.VERSION_CODES.TIRAMISU)
-public class NsdShimImpl extends com.android.networkstack.apishim.api31.NsdShimImpl {
-
- /**
- * Get a new instance of {@link NsdShim}.
- */
- @RequiresApi(Build.VERSION_CODES.Q)
- public static NsdShim newInstance() {
- if (SdkLevel.isAtLeastT()) {
- return new NsdShimImpl();
- } else {
- return new com.android.networkstack.apishim.api31.NsdShimImpl();
- }
- }
-
- @Nullable
- @Override
- public Network getNetwork(@NonNull NsdServiceInfo serviceInfo) {
- return serviceInfo.getNetwork();
- }
-
- @Override
- public void setNetwork(@NonNull NsdServiceInfo serviceInfo, @Nullable Network network) {
- serviceInfo.setNetwork(network);
- }
-
- @Override
- public void registerService(@NonNull NsdManager nsdManager, @NonNull NsdServiceInfo serviceInfo,
- int protocolType, @NonNull Executor executor,
- @NonNull NsdManager.RegistrationListener listener) {
- nsdManager.registerService(serviceInfo, protocolType, executor, listener);
- }
-
- @Override
- public void discoverServices(@NonNull NsdManager nsdManager, @NonNull String serviceType,
- int protocolType, @Nullable Network network,
- @NonNull Executor executor, @NonNull NsdManager.DiscoveryListener listener)
- throws UnsupportedApiLevelException {
- nsdManager.discoverServices(serviceType, protocolType, network, executor, listener);
- }
-
- @Override
- public void discoverServices(@NonNull NsdManager nsdManager, @NonNull String serviceType,
- int protocolType, @Nullable NetworkRequest request,
- @NonNull Executor executor, @NonNull NsdManager.DiscoveryListener listener)
- throws UnsupportedApiLevelException {
- nsdManager.discoverServices(serviceType, protocolType, request, executor, listener);
- }
-
- @Override
- public void resolveService(@NonNull NsdManager nsdManager, @NonNull NsdServiceInfo serviceInfo,
- @NonNull Executor executor, @NonNull NsdManager.ResolveListener resolveListener)
- throws UnsupportedApiLevelException {
- nsdManager.resolveService(serviceInfo, executor, resolveListener);
- }
-}
diff --git a/apishim/34/com/android/networkstack/apishim/api34/NsdShimImpl.java b/apishim/34/com/android/networkstack/apishim/api34/NsdShimImpl.java
deleted file mode 100644
index fc37b30..0000000
--- a/apishim/34/com/android/networkstack/apishim/api34/NsdShimImpl.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * Copyright (C) 2022 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.networkstack.apishim.api34;
-
-import android.net.nsd.NsdManager;
-import android.net.nsd.NsdServiceInfo;
-import android.os.Build;
-import android.util.ArrayMap;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.RequiresApi;
-
-import com.android.modules.utils.build.SdkLevel;
-import com.android.networkstack.apishim.common.NsdShim;
-import com.android.networkstack.apishim.common.UnsupportedApiLevelException;
-
-import java.net.InetAddress;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.concurrent.Executor;
-
-/**
- * Implementation of {@link NsdShim}.
- */
-@RequiresApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
-public class NsdShimImpl extends com.android.networkstack.apishim.api33.NsdShimImpl {
- private final Map<ServiceInfoCallbackShim, ServiceInfoCallbackWrapper> mCbWrappers =
- Collections.synchronizedMap(new ArrayMap<>());
-
- /**
- * Get a new instance of {@link NsdShim}.
- */
- @RequiresApi(Build.VERSION_CODES.Q)
- public static NsdShim newInstance() {
- if (SdkLevel.isAtLeastU()) {
- return new NsdShimImpl();
- } else {
- return new com.android.networkstack.apishim.api33.NsdShimImpl();
- }
- }
-
- @Override
- public void stopServiceResolution(@NonNull NsdManager nsdManager,
- @NonNull NsdManager.ResolveListener resolveListener)
- throws UnsupportedApiLevelException {
- nsdManager.stopServiceResolution(resolveListener);
- }
-
- private static class ServiceInfoCallbackWrapper implements NsdManager.ServiceInfoCallback {
- @NonNull
- final ServiceInfoCallbackShim mListener;
-
- ServiceInfoCallbackWrapper(@NonNull ServiceInfoCallbackShim listener) {
- mListener = listener;
- }
-
- @Override
- public void onServiceInfoCallbackRegistrationFailed(int errorCode) {
- mListener.onServiceInfoCallbackRegistrationFailed(errorCode);
- }
-
- @Override
- public void onServiceUpdated(@NonNull NsdServiceInfo serviceInfo) {
- mListener.onServiceUpdated(serviceInfo);
- }
-
- @Override
- public void onServiceLost() {
- mListener.onServiceLost();
- }
-
- @Override
- public void onServiceInfoCallbackUnregistered() {
- mListener.onServiceInfoCallbackUnregistered();
- }
- };
-
- @Override
- public void registerServiceInfoCallback(@NonNull NsdManager nsdManager,
- @NonNull NsdServiceInfo serviceInfo, @NonNull Executor executor,
- @NonNull ServiceInfoCallbackShim listener) throws UnsupportedApiLevelException {
- Objects.requireNonNull(listener);
- final ServiceInfoCallbackWrapper wrapper = new ServiceInfoCallbackWrapper(listener);
- if (null != mCbWrappers.put(listener, wrapper)) {
- throw new IllegalArgumentException("Listener shims must not be reused");
- }
- nsdManager.registerServiceInfoCallback(serviceInfo, executor, wrapper);
- }
-
- @Override
- public void unregisterServiceInfoCallback(@NonNull NsdManager nsdManager,
- @NonNull ServiceInfoCallbackShim listener) throws UnsupportedApiLevelException {
- final ServiceInfoCallbackWrapper wrapper = mCbWrappers.remove(listener);
- if (wrapper == null) {
- throw new IllegalArgumentException("Listener was not registered");
- }
- nsdManager.unregisterServiceInfoCallback(wrapper);
- }
-
- @NonNull
- @Override
- public List<InetAddress> getHostAddresses(@NonNull NsdServiceInfo serviceInfo) {
- return serviceInfo.getHostAddresses();
- }
-
- @Override
- public void setHostAddresses(@NonNull NsdServiceInfo serviceInfo,
- @NonNull List<InetAddress> addresses) {
- serviceInfo.setHostAddresses(addresses);
- }
-}
diff --git a/apishim/35/com/android/networkstack/apishim/NsdShimImpl.java b/apishim/35/com/android/networkstack/apishim/NsdShimImpl.java
deleted file mode 100644
index 4b992ee..0000000
--- a/apishim/35/com/android/networkstack/apishim/NsdShimImpl.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright (C) 2023 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.networkstack.apishim;
-
-import android.os.Build;
-
-import androidx.annotation.RequiresApi;
-
-import com.android.networkstack.apishim.common.NsdShim;
-
-/**
- * Implementation of {@link NsdShim}.
- */
-// TODO: when available in all active branches: @RequiresApi(Build.VERSION_CODES.VANILLA_ICE_CREAM)
-@RequiresApi(Build.VERSION_CODES.CUR_DEVELOPMENT)
-public class NsdShimImpl extends com.android.networkstack.apishim.api34.NsdShimImpl {
- // Inherit everything from API34 shim
-}
diff --git a/apishim/common/com/android/networkstack/apishim/common/NsdShim.java b/apishim/common/com/android/networkstack/apishim/common/NsdShim.java
deleted file mode 100644
index 7281022..0000000
--- a/apishim/common/com/android/networkstack/apishim/common/NsdShim.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * Copyright (C) 2022 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.networkstack.apishim.common;
-
-import android.net.Network;
-import android.net.NetworkRequest;
-import android.net.nsd.NsdManager;
-import android.net.nsd.NsdManager.DiscoveryListener;
-import android.net.nsd.NsdManager.RegistrationListener;
-import android.net.nsd.NsdManager.ResolveListener;
-import android.net.nsd.NsdServiceInfo;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-
-import java.net.InetAddress;
-import java.util.List;
-import java.util.concurrent.Executor;
-
-/** Shim for NSD APIs, including {@link android.net.nsd.NsdManager} and
- * {@link android.net.nsd.NsdServiceInfo}. */
-public interface NsdShim {
- /**
- * @see NsdServiceInfo#getNetwork()
- */
- @Nullable
- Network getNetwork(@NonNull NsdServiceInfo serviceInfo);
-
- /**
- * @see NsdServiceInfo#setNetwork(Network)
- */
- void setNetwork(@NonNull NsdServiceInfo serviceInfo, @Nullable Network network);
-
- /**
- * @see NsdManager#registerService(NsdServiceInfo, int, Executor, RegistrationListener)
- */
- void registerService(@NonNull NsdManager nsdManager, @NonNull NsdServiceInfo serviceInfo,
- int protocolType, @NonNull Executor executor, @NonNull RegistrationListener listener)
- throws UnsupportedApiLevelException;
-
- /**
- * @see NsdManager#discoverServices(String, int, Network, Executor, DiscoveryListener)
- */
- void discoverServices(@NonNull NsdManager nsdManager, @NonNull String serviceType,
- int protocolType, @Nullable Network network,
- @NonNull Executor executor, @NonNull DiscoveryListener listener)
- throws UnsupportedApiLevelException;
-
- /**
- * @see NsdManager#resolveService(NsdServiceInfo, Executor, ResolveListener)
- */
- void resolveService(@NonNull NsdManager nsdManager, @NonNull NsdServiceInfo serviceInfo,
- @NonNull Executor executor, @NonNull ResolveListener resolveListener)
- throws UnsupportedApiLevelException;
-
- /**
- * @see NsdManager#discoverServices(String, int, NetworkRequest, Executor, DiscoveryListener)
- */
- void discoverServices(@NonNull NsdManager nsdManager, @NonNull String serviceType,
- int protocolType, @Nullable NetworkRequest request,
- @NonNull Executor executor, @NonNull DiscoveryListener listener)
- throws UnsupportedApiLevelException;
-
- /**
- * @see NsdManager#stopServiceResolution(ResolveListener)
- */
- void stopServiceResolution(@NonNull NsdManager nsdManager,
- @NonNull ResolveListener resolveListener) throws UnsupportedApiLevelException;
-
- /**
- * @see NsdManager#ServiceInfoCallback
- */
- interface ServiceInfoCallbackShim {
- default void onServiceInfoCallbackRegistrationFailed(int errorCode) {}
- default void onServiceUpdated(@NonNull NsdServiceInfo serviceInfo) {}
- default void onServiceLost() {}
- default void onServiceInfoCallbackUnregistered() {}
- }
-
- /**
- * @see NsdManager#registerServiceInfoCallback
- */
- default void registerServiceInfoCallback(@NonNull NsdManager nsdManager,
- @NonNull NsdServiceInfo serviceInfo, @NonNull Executor executor,
- @NonNull ServiceInfoCallbackShim listener)
- throws UnsupportedApiLevelException {
- throw new UnsupportedApiLevelException("Service callback is only supported on U+");
- }
-
- /**
- * @see NsdManager#unregisterServiceInfoCallback
- */
- default void unregisterServiceInfoCallback(@NonNull NsdManager nsdManager,
- @NonNull ServiceInfoCallbackShim listener)
- throws UnsupportedApiLevelException {
- throw new UnsupportedApiLevelException("Service callback is only supported on U+");
- }
-
- /**
- * @see NsdServiceInfo#getHostAddresses()
- */
- @NonNull
- default List<InetAddress> getHostAddresses(@NonNull NsdServiceInfo serviceInfo)
- throws UnsupportedApiLevelException {
- throw new UnsupportedApiLevelException("getHostAddresses is only supported on U+");
- }
-
- /**
- * @see NsdServiceInfo#setHostAddresses(List<InetAddress>)
- */
- default void setHostAddresses(@NonNull NsdServiceInfo serviceInfo,
- @NonNull List<InetAddress> addresses) throws UnsupportedApiLevelException {
- throw new UnsupportedApiLevelException("setHostAddresses is only supported on U+");
- }
-}