Merge changes I095a869f,I587dfebb into sc-dev am: a694e6fa56

Original change: https://googleplex-android-review.googlesource.com/c/platform/cts/+/15165943

Change-Id: I5dab3f133c6683bc064cffad1c183fe6ef6c7590
diff --git a/hostsidetests/edi/Android.bp b/hostsidetests/edi/Android.bp
index 3f4bac8..1b32a4b 100644
--- a/hostsidetests/edi/Android.bp
+++ b/hostsidetests/edi/Android.bp
@@ -33,6 +33,7 @@
     ],
     static_libs: [
         "compat-classpaths-testing",
+        "modules-utils-build-testing",
         "hamcrest-library",
     ],
 }
diff --git a/hostsidetests/edi/app/Android.bp b/hostsidetests/edi/app/Android.bp
index 6ef3059..96f2870 100644
--- a/hostsidetests/edi/app/Android.bp
+++ b/hostsidetests/edi/app/Android.bp
@@ -20,9 +20,12 @@
     name: "CtsDeviceInfoTestApp",
     srcs: ["src/**/*.java"],
     defaults: ["cts_defaults"],
+    min_sdk_version: "26",
+    target_sdk_version: "31",
     static_libs: [
         "androidx.test.rules",
         "androidx.test.core",
+        "modules-utils-build",
         "guava",
     ],
     sdk_version: "test_current",
diff --git a/hostsidetests/edi/app/AndroidManifest.xml b/hostsidetests/edi/app/AndroidManifest.xml
index 00206b7..2f589dc 100644
--- a/hostsidetests/edi/app/AndroidManifest.xml
+++ b/hostsidetests/edi/app/AndroidManifest.xml
@@ -19,6 +19,8 @@
           package="android.edi.cts.app"
           android:targetSandboxVersion="2">
 
+    <uses-sdk android:minSdkVersion="26" android:targetSdkVersion="31"/>
+
     <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
     <uses-permission android:name="android.permission.ACCESS_SHARED_LIBRARIES" />
 
diff --git a/hostsidetests/edi/app/src/android/edi/cts/app/ClasspathDeviceTest.java b/hostsidetests/edi/app/src/android/edi/cts/app/ClasspathDeviceTest.java
index a68d626..5c22e43 100644
--- a/hostsidetests/edi/app/src/android/edi/cts/app/ClasspathDeviceTest.java
+++ b/hostsidetests/edi/app/src/android/edi/cts/app/ClasspathDeviceTest.java
@@ -16,6 +16,8 @@
 
 package android.edi.cts.app;
 
+import static org.junit.Assume.assumeTrue;
+
 import android.app.Instrumentation;
 import android.content.Context;
 import android.content.pm.SharedLibraryInfo;
@@ -24,6 +26,8 @@
 import androidx.test.platform.app.InstrumentationRegistry;
 import androidx.test.runner.AndroidJUnit4;
 
+import com.android.modules.utils.build.SdkLevel;
+
 import com.google.common.collect.ImmutableList;
 
 import org.junit.After;
@@ -53,6 +57,7 @@
 
     @Before
     public void before() {
+        assumeTrue(SdkLevel.isAtLeastS());
         instrumentation.getUiAutomation().adoptShellPermissionIdentity();
     }
 
diff --git a/hostsidetests/edi/src/android/edi/cts/ClasspathDeviceInfo.java b/hostsidetests/edi/src/android/edi/cts/ClasspathDeviceInfo.java
index 2785ab2..8fc1059 100644
--- a/hostsidetests/edi/src/android/edi/cts/ClasspathDeviceInfo.java
+++ b/hostsidetests/edi/src/android/edi/cts/ClasspathDeviceInfo.java
@@ -26,6 +26,7 @@
 
 import com.android.compatibility.common.util.DeviceInfo;
 import com.android.compatibility.common.util.HostInfoStore;
+import com.android.modules.utils.build.testing.DeviceSdkLevel;
 import com.android.tradefed.device.ITestDevice;
 import com.android.tradefed.log.LogUtil.CLog;
 
@@ -44,10 +45,12 @@
     private static final String HELPER_APP_CLASS = HELPER_APP_PACKAGE + ".ClasspathDeviceTest";
 
     private ITestDevice mDevice;
+    private DeviceSdkLevel deviceSdkLevel;
 
     @Override
     protected void collectDeviceInfo(HostInfoStore store) throws Exception {
         mDevice = getDevice();
+        deviceSdkLevel = new DeviceSdkLevel(mDevice);
 
         store.startArray("jars");
         collectClasspathsJars(store);
@@ -75,6 +78,10 @@
     }
 
     private void collectSharedLibraryJars(HostInfoStore store) throws Exception {
+        if (!deviceSdkLevel.isDeviceAtLeastS()) {
+            return;
+        }
+
         // Trigger helper app to collect and write info about shared libraries on the device.
         assertThat(runDeviceTests(HELPER_APP_PACKAGE, HELPER_APP_CLASS)).isTrue();