[SP28.2] Add shims to allow test utils built against different SDKs
Test: build pass with or without aosp/1469125 in frameworks/base
Test: atest NetworkStatsServiceTest TetheringTests
Bug: 149467454
Change-Id: Ie3971ed3b18e0f1a54d4834e310bc6df82e5acdd
diff --git a/staticlibs/devicetests/com/android/testutils/NetworkStatsProviderCbStubCompat.java b/staticlibs/devicetests/com/android/testutils/NetworkStatsProviderCbStubCompat.java
new file mode 100644
index 0000000..e84a224
--- /dev/null
+++ b/staticlibs/devicetests/com/android/testutils/NetworkStatsProviderCbStubCompat.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2021 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.testutils;
+
+import android.net.NetworkStats;
+import android.net.netstats.provider.INetworkStatsProviderCallback;
+import android.os.RemoteException;
+
+/**
+ * A shim class that allows {@link TestableNetworkStatsProviderCbBinder} to be built against
+ * different SDK versions.
+ */
+public class NetworkStatsProviderCbStubCompat extends INetworkStatsProviderCallback.Stub {
+ @Override
+ public void notifyStatsUpdated(int token, NetworkStats ifaceStats, NetworkStats uidStats)
+ throws RemoteException {}
+
+ @Override
+ public void notifyAlertReached() throws RemoteException {}
+
+ // Removed in S.
+ public void notifyLimitReached() throws RemoteException {}
+
+ // Added in S.
+ public void notifyWarningOrLimitReached() throws RemoteException {}
+
+ @Override
+ public void unregister() throws RemoteException {}
+}
diff --git a/staticlibs/devicetests/com/android/testutils/NetworkStatsProviderStubCompat.java b/staticlibs/devicetests/com/android/testutils/NetworkStatsProviderStubCompat.java
new file mode 100644
index 0000000..a77aa02
--- /dev/null
+++ b/staticlibs/devicetests/com/android/testutils/NetworkStatsProviderStubCompat.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2021 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.testutils;
+
+import android.net.netstats.provider.INetworkStatsProvider;
+
+/**
+ * A shim class that allows {@link TestableNetworkStatsProviderBinder} to be built against
+ * different SDK versions.
+ */
+public class NetworkStatsProviderStubCompat extends INetworkStatsProvider.Stub {
+ @Override
+ public void onRequestStatsUpdate(int token) {}
+
+ // Removed and won't be called in S+.
+ public void onSetLimit(String iface, long quotaBytes) {}
+
+ @Override
+ public void onSetAlert(long bytes) {}
+
+ // Added in S.
+ public void onSetWarningAndLimit(String iface, long warningBytes, long limitBytes) {}
+}
diff --git a/staticlibs/devicetests/com/android/testutils/TestableNetworkStatsProviderBinder.kt b/staticlibs/devicetests/com/android/testutils/TestableNetworkStatsProviderBinder.kt
index 02922d8..d71f604 100644
--- a/staticlibs/devicetests/com/android/testutils/TestableNetworkStatsProviderBinder.kt
+++ b/staticlibs/devicetests/com/android/testutils/TestableNetworkStatsProviderBinder.kt
@@ -16,14 +16,13 @@
package com.android.testutils
-import android.net.netstats.provider.INetworkStatsProvider
import com.android.net.module.util.ArrayTrackRecord
import kotlin.test.assertEquals
import kotlin.test.fail
private const val DEFAULT_TIMEOUT_MS = 200L
-open class TestableNetworkStatsProviderBinder : INetworkStatsProvider.Stub() {
+open class TestableNetworkStatsProviderBinder : NetworkStatsProviderStubCompat() {
sealed class CallbackType {
data class OnRequestStatsUpdate(val token: Int) : CallbackType()
data class OnSetLimit(val iface: String?, val quotaBytes: Long) : CallbackType()
diff --git a/staticlibs/devicetests/com/android/testutils/TestableNetworkStatsProviderCbBinder.kt b/staticlibs/devicetests/com/android/testutils/TestableNetworkStatsProviderCbBinder.kt
index 163473a..ea6b1dc 100644
--- a/staticlibs/devicetests/com/android/testutils/TestableNetworkStatsProviderCbBinder.kt
+++ b/staticlibs/devicetests/com/android/testutils/TestableNetworkStatsProviderCbBinder.kt
@@ -17,7 +17,6 @@
package com.android.testutils
import android.net.NetworkStats
-import android.net.netstats.provider.INetworkStatsProviderCallback
import com.android.net.module.util.ArrayTrackRecord
import kotlin.test.assertEquals
import kotlin.test.assertTrue
@@ -25,7 +24,7 @@
private const val DEFAULT_TIMEOUT_MS = 3000L
-open class TestableNetworkStatsProviderCbBinder : INetworkStatsProviderCallback.Stub() {
+open class TestableNetworkStatsProviderCbBinder : NetworkStatsProviderCbStubCompat() {
sealed class CallbackType {
data class NotifyStatsUpdated(
val token: Int,