diff options
-rw-r--r-- | tests/unit/jni/Android.bp | 7 | ||||
-rw-r--r-- | tests/unit/jni/apf_jni.cpp | 5 | ||||
-rw-r--r-- | tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java | 43 |
3 files changed, 44 insertions, 11 deletions
diff --git a/tests/unit/jni/Android.bp b/tests/unit/jni/Android.bp index 4bef7c8..fa1f420 100644 --- a/tests/unit/jni/Android.bp +++ b/tests/unit/jni/Android.bp @@ -28,14 +28,13 @@ cc_library_shared { "hardware/google/apf", ], shared_libs: [ - "libbinder", "liblog", - "libcutils", - "libnativehelper", - "netd_aidl_interface-cpp", + "libnativehelper_compat_libc++", ], static_libs: [ "libapf", "libpcap", ], + sdk_version: "29", + stl: "c++_static", } diff --git a/tests/unit/jni/apf_jni.cpp b/tests/unit/jni/apf_jni.cpp index 4222adf..ff30bd1 100644 --- a/tests/unit/jni/apf_jni.cpp +++ b/tests/unit/jni/apf_jni.cpp @@ -14,19 +14,20 @@ * limitations under the License. */ +#include <android/log.h> #include <nativehelper/JNIHelp.h> #include <nativehelper/ScopedUtfChars.h> #include <jni.h> #include <pcap.h> #include <stdlib.h> #include <string> -#include <utils/Log.h> #include <vector> #include "apf_interpreter.h" #include "nativehelper/scoped_primitive_array.h" #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) +#define LOG_TAG "NetworkStackUtils-JNI" // JNI function acting as simply call-through to native APF interpreter. static jint com_android_server_ApfTest_apfSimulate( @@ -226,7 +227,7 @@ static jboolean com_android_server_ApfTest_dropsAllPackets(JNIEnv* env, jclass, extern "C" jint JNI_OnLoad(JavaVM* vm, void*) { JNIEnv *env; if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) { - ALOGE("ERROR: GetEnv failed"); + __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "ERROR: GetEnv failed"); return -1; } diff --git a/tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java b/tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java index 7a34c59..ae234b1 100644 --- a/tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java +++ b/tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java @@ -83,6 +83,7 @@ import android.net.shared.PrivateDnsConfig; import android.net.util.SharedLog; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; +import android.os.Build; import android.os.Bundle; import android.os.ConditionVariable; import android.os.Handler; @@ -105,6 +106,7 @@ import androidx.test.runner.AndroidJUnit4; import com.android.internal.util.CollectionUtils; import com.android.networkstack.R; +import com.android.networkstack.apishim.ShimUtils; import com.android.networkstack.metrics.DataStallDetectionStats; import com.android.networkstack.metrics.DataStallStatsUtils; import com.android.networkstack.netlink.TcpSocketTracker; @@ -123,6 +125,7 @@ import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import java.io.IOException; +import java.lang.reflect.Constructor; import java.net.HttpURLConnection; import java.net.InetAddress; import java.net.URL; @@ -542,11 +545,10 @@ public class NetworkMonitorTest { final CellInfoGsm cellInfoGsm1 = new CellInfoGsm(); final CellInfoGsm cellInfoGsm2 = new CellInfoGsm(); final CellInfoLte cellInfoLte = new CellInfoLte(); - final CellIdentityGsm cellIdentityGsm = - new CellIdentityGsm(0, 0, 0, 0, "460", "01", "", "", Collections.emptyList()); - final CellIdentityLte cellIdentityLte = - new CellIdentityLte(0, 0, 0, 0, 0, "466", "01", "", "", - Collections.emptyList(), null); + final CellIdentityGsm cellIdentityGsm = makeCellIdentityGsm( + 0, 0, 0, 0, "460", "01", "", ""); + final CellIdentityLte cellIdentityLte = makeCellIdentityLte( + 0, 0, 0, 0, 0, "466", "01", "", ""); cellInfoGsm1.setCellIdentity(cellIdentityGsm); cellInfoGsm2.setCellIdentity(cellIdentityGsm); cellInfoLte.setCellIdentity(cellIdentityLte); @@ -569,6 +571,37 @@ public class NetworkMonitorTest { assertEquals(wnm.getContext(), wnm.getContextByMccIfNoSimCardOrDefault()); } + private static CellIdentityGsm makeCellIdentityGsm(int lac, int cid, int arfcn, int bsic, + String mccStr, String mncStr, String alphal, String alphas) + throws ReflectiveOperationException { + if (ShimUtils.isReleaseOrDevelopmentApiAbove(Build.VERSION_CODES.Q)) { + return new CellIdentityGsm(lac, cid, arfcn, bsic, mccStr, mncStr, alphal, alphas, + Collections.emptyList() /* additionalPlmns */); + } else { + // API <= Q does not have the additionalPlmns parameter + final Constructor<CellIdentityGsm> constructor = CellIdentityGsm.class.getConstructor( + int.class, int.class, int.class, int.class, String.class, String.class, + String.class, String.class); + return constructor.newInstance(lac, cid, arfcn, bsic, mccStr, mncStr, alphal, alphas); + } + } + + private static CellIdentityLte makeCellIdentityLte(int ci, int pci, int tac, int earfcn, + int bandwidth, String mccStr, String mncStr, String alphal, String alphas) + throws ReflectiveOperationException { + if (ShimUtils.isReleaseOrDevelopmentApiAbove(Build.VERSION_CODES.Q)) { + return new CellIdentityLte(ci, pci, tac, earfcn, bandwidth, mccStr, mncStr, alphal, + alphas, Collections.emptyList() /* additionalPlmns */, null /* csgInfo */); + } else { + // API <= Q does not have the additionalPlmns and csgInfo parameters + final Constructor<CellIdentityLte> constructor = CellIdentityLte.class.getConstructor( + int.class, int.class, int.class, int.class, int.class, String.class, + String.class, String.class, String.class); + return constructor.newInstance(ci, pci, tac, earfcn, bandwidth, mccStr, mncStr, alphal, + alphas); + } + } + @Test public void testGetIntSetting() throws Exception { WrappedNetworkMonitor wnm = makeNotMeteredNetworkMonitor(); |