Merge "Add tests for data partition sizes" into stage-aosp-pi-cts-dev
diff --git a/apps/CtsVerifier/AndroidManifest.xml b/apps/CtsVerifier/AndroidManifest.xml
index 7f367db..e054d11 100644
--- a/apps/CtsVerifier/AndroidManifest.xml
+++ b/apps/CtsVerifier/AndroidManifest.xml
@@ -2217,7 +2217,7 @@
             </intent-filter>
             <meta-data android:name="test_category" android:value="@string/test_category_deskclock" />
             <meta-data android:name="test_excluded_features"
-                    android:value="android.hardware.type.television:android.software.leanback" />
+                    android:value="android.hardware.type.television:android.software.leanback:android.hardware.type.automotive" />
         </activity>
 
 <!-- TODO: enable when not requiring to tap the screen and timeouts are tuned -->
diff --git a/common/device-side/util/src/com/android/compatibility/common/util/AppOpsUtils.java b/common/device-side/util/src/com/android/compatibility/common/util/AppOpsUtils.java
index 20c5b9e..939d6da 100644
--- a/common/device-side/util/src/com/android/compatibility/common/util/AppOpsUtils.java
+++ b/common/device-side/util/src/com/android/compatibility/common/util/AppOpsUtils.java
@@ -74,6 +74,25 @@
     }
 
     /**
+     * Get the app op mode (e.g. MODE_ALLOWED, MODE_DEFAULT) for a single package and operation.
+     */
+    public static int getOpMode(String packageName, String opStr)
+            throws IOException {
+        String opState = getOpState(packageName, opStr);
+        if (opState.contains(" allow")) {
+            return MODE_ALLOWED;
+        } else if (opState.contains(" deny")) {
+            return MODE_ERRORED;
+        } else if (opState.contains(" ignore")) {
+            return MODE_IGNORED;
+        } else if (opState.contains(" default")) {
+            return MODE_DEFAULT;
+        } else {
+            throw new IllegalStateException("Unexpected app op mode returned " + opState);
+        }
+    }
+
+    /**
      * Returns whether an allowed operation has been logged by the AppOpsManager for a
      * package. Operations are noted when the app attempts to perform them and calls e.g.
      * {@link AppOpsManager#noteOperation}.
@@ -86,7 +105,7 @@
     }
 
     /**
-     * Returns whether an allowed operation has been logged by the AppOpsManager for a
+     * Returns whether a rejected operation has been logged by the AppOpsManager for a
      * package. Operations are noted when the app attempts to perform them and calls e.g.
      * {@link AppOpsManager#noteOperation}.
      *
@@ -110,4 +129,4 @@
     private static String runCommand(String command) throws IOException {
         return SystemUtil.runShellCommand(InstrumentationRegistry.getInstrumentation(), command);
     }
-}
\ No newline at end of file
+}
diff --git a/hostsidetests/statsd/src/android/cts/statsd/atom/HostAtomTests.java b/hostsidetests/statsd/src/android/cts/statsd/atom/HostAtomTests.java
index b91ebbb..52f6d30 100644
--- a/hostsidetests/statsd/src/android/cts/statsd/atom/HostAtomTests.java
+++ b/hostsidetests/statsd/src/android/cts/statsd/atom/HostAtomTests.java
@@ -15,37 +15,22 @@
  */
 package android.cts.statsd.atom;
 
-import android.os.BatteryPluggedStateEnum; // From os/enums.proto
-import android.os.BatteryStatusEnum; // From os/enums.proto
+import android.os.BatteryPluggedStateEnum;
+import android.os.BatteryStatusEnum;
 import android.platform.test.annotations.RestrictedBuildTest;
-import android.server.DeviceIdleModeEnum; // From server/enums.proto
-import android.view.DisplayStateEnum; // From view/enums.proto
+import android.server.DeviceIdleModeEnum;
+import android.view.DisplayStateEnum;
 
-import com.android.internal.os.StatsdConfigProto.Alert;
-import com.android.internal.os.StatsdConfigProto.CountMetric;
-import com.android.internal.os.StatsdConfigProto.DurationMetric;
-import com.android.internal.os.StatsdConfigProto.FieldFilter;
 import com.android.internal.os.StatsdConfigProto.FieldMatcher;
-import com.android.internal.os.StatsdConfigProto.GaugeMetric;
-import com.android.internal.os.StatsdConfigProto.IncidentdDetails;
 import com.android.internal.os.StatsdConfigProto.StatsdConfig;
-import com.android.internal.os.StatsdConfigProto.Subscription;
-import com.android.internal.os.StatsdConfigProto.TimeUnit;
-import com.android.internal.os.StatsdConfigProto.ValueMetric;
 import com.android.os.AtomsProto.AppBreadcrumbReported;
 import com.android.os.AtomsProto.Atom;
 import com.android.os.AtomsProto.BatterySaverModeStateChanged;
-import com.android.os.AtomsProto.ChargingStateChanged;
-import com.android.os.AtomsProto.CpuTimePerFreq;
-import com.android.os.AtomsProto.DeviceIdleModeStateChanged;
 import com.android.os.AtomsProto.FullBatteryCapacity;
 import com.android.os.AtomsProto.KernelWakelock;
-import com.android.os.AtomsProto.PluggedStateChanged;
 import com.android.os.AtomsProto.RemainingBatteryCapacity;
-import com.android.os.AtomsProto.ScreenStateChanged;
 import com.android.os.AtomsProto.SubsystemSleepState;
 import com.android.os.StatsLog.EventMetricData;
-import com.android.tradefed.log.LogUtil.CLog;
 
 import java.util.Arrays;
 import java.util.HashSet;
@@ -424,32 +409,6 @@
         assertTrue(atom.getKernelWakelock().hasTime());
     }
 
-    public void testCpuTimePerFreq() throws Exception {
-        if (statsdDisabled()) {
-            return;
-        }
-        if (!hasFeature(FEATURE_WATCH, false)) return;
-        StatsdConfig.Builder config = getPulledConfig();
-        FieldMatcher.Builder dimension = FieldMatcher.newBuilder()
-                .setField(Atom.CPU_TIME_PER_FREQ_FIELD_NUMBER)
-                .addChild(FieldMatcher.newBuilder()
-                        .setField(CpuTimePerFreq.CLUSTER_FIELD_NUMBER));
-        addGaugeAtom(config, Atom.CPU_TIME_PER_FREQ_FIELD_NUMBER, dimension);
-
-        uploadConfig(config);
-
-        Thread.sleep(WAIT_TIME_LONG);
-        setAppBreadcrumbPredicate();
-        Thread.sleep(WAIT_TIME_LONG);
-
-        List<Atom> data = getGaugeMetricDataList();
-
-        Atom atom = data.get(0);
-        assertTrue(atom.getCpuTimePerFreq().getCluster() >= 0);
-        assertTrue(atom.getCpuTimePerFreq().getFreqIndex() >= 0);
-        assertTrue(atom.getCpuTimePerFreq().getTimeMillis() > 0);
-    }
-
     public void testSubsystemSleepState() throws Exception {
         if (statsdDisabled()) {
             return;
diff --git a/tests/framework/base/activitymanager/src/android/server/am/lifecycle/ActivityLifecycleTests.java b/tests/framework/base/activitymanager/src/android/server/am/lifecycle/ActivityLifecycleTests.java
index 881d002..a381d04 100644
--- a/tests/framework/base/activitymanager/src/android/server/am/lifecycle/ActivityLifecycleTests.java
+++ b/tests/framework/base/activitymanager/src/android/server/am/lifecycle/ActivityLifecycleTests.java
@@ -715,15 +715,15 @@
         InstrumentationRegistry.getTargetContext().startActivity(intent);
 
         // Wait for the activity to resume again
-        final List<LifecycleLog.ActivityCallback> expectedSequence =
-                Arrays.asList(ON_NEW_INTENT, ON_RESUME);
-        waitForActivityTransitions(SingleTopActivity.class, expectedSequence);
-
-        // Verify that the new intent was delivered and resumed again
         // TODO(b/77974794): New intent handling sequence should always be the same.
         // It is possible to get an extra pause and resume now.
         final List<LifecycleLog.ActivityCallback> extraPauseSequence =
                 Arrays.asList(ON_NEW_INTENT, ON_RESUME, ON_PAUSE, ON_RESUME);
+        waitForActivityTransitions(SingleTopActivity.class, extraPauseSequence);
+
+        // Verify that the new intent was delivered and resumed again
+        final List<LifecycleLog.ActivityCallback> expectedSequence =
+                Arrays.asList(ON_NEW_INTENT, ON_RESUME);
         LifecycleVerifier.assertSequenceMatchesOneOf(SingleTopActivity.class, getLifecycleLog(),
                 Arrays.asList(expectedSequence, extraPauseSequence), "newIntent");
     }
diff --git a/tests/tests/keystore/src/android/keystore/cts/AndroidKeyStoreTest.java b/tests/tests/keystore/src/android/keystore/cts/AndroidKeyStoreTest.java
index b09a679..7db0f61 100644
--- a/tests/tests/keystore/src/android/keystore/cts/AndroidKeyStoreTest.java
+++ b/tests/tests/keystore/src/android/keystore/cts/AndroidKeyStoreTest.java
@@ -63,6 +63,7 @@
 
 import javax.crypto.BadPaddingException;
 import javax.crypto.Cipher;
+import javax.crypto.IllegalBlockSizeException;
 import javax.crypto.Mac;
 import javax.crypto.SecretKey;
 import javax.security.auth.x500.X500Principal;
@@ -1967,9 +1968,11 @@
         // is bigger than the modulus.
         try {
             encrypt.doFinal(plainText);
-            fail("Expected BadPaddingException");
+            fail("Expected BadPaddingException or IllegalBlockSizeException");
         } catch (BadPaddingException e) {
             // pass on exception as it is expected
+        } catch (IllegalBlockSizeException e) {
+            // pass on exception as it is expected
         }
     }
 
diff --git a/tests/tests/keystore/src/android/keystore/cts/KeyAttestationTest.java b/tests/tests/keystore/src/android/keystore/cts/KeyAttestationTest.java
index 0342f08..80e28d1 100644
--- a/tests/tests/keystore/src/android/keystore/cts/KeyAttestationTest.java
+++ b/tests/tests/keystore/src/android/keystore/cts/KeyAttestationTest.java
@@ -718,8 +718,8 @@
 
     @SuppressWarnings("unchecked")
     private void checkAttestationSecurityLevelDependentParams(Attestation attestation) {
-        assertThat("Attestation version must be 1 or 2", attestation.getAttestationVersion(),
-                either(is(1)).or(is(2)));
+        assertThat("Attestation version must be 1, 2, or 3", attestation.getAttestationVersion(),
+               either(is(1)).or(is(2)).or(is(3)));
 
         AuthorizationList teeEnforced = attestation.getTeeEnforced();
         AuthorizationList softwareEnforced = attestation.getSoftwareEnforced();
@@ -732,7 +732,7 @@
                 assertThat("TEE attestation can only come from TEE keymaster",
                         attestation.getKeymasterSecurityLevel(),
                         is(KM_SECURITY_LEVEL_TRUSTED_ENVIRONMENT));
-                assertThat(attestation.getKeymasterVersion(), either(is(2)).or(is(3)));
+                assertThat(attestation.getKeymasterVersion(), either(is(2)).or(is(3)).or(is(4)));
 
                 checkRootOfTrust(attestation);
                 assertThat(teeEnforced.getOsVersion(), is(systemOsVersion));
diff --git a/tests/tests/keystore/src/android/server/am/ActivityManagerTestBase.java b/tests/tests/keystore/src/android/server/am/ActivityManagerTestBase.java
index 87f80b0..b960d2f 100644
--- a/tests/tests/keystore/src/android/server/am/ActivityManagerTestBase.java
+++ b/tests/tests/keystore/src/android/server/am/ActivityManagerTestBase.java
@@ -33,6 +33,7 @@
 import static android.server.am.UiDeviceUtils.pressWakeupButton;
 import static android.server.am.UiDeviceUtils.waitForDeviceIdle;
 
+import android.accessibilityservice.AccessibilityService;
 import android.app.ActivityManager;
 import android.content.ComponentName;
 import android.content.Context;
@@ -297,6 +298,11 @@
 
         public LockScreenSession sleepDevice() {
             pressSleepButton();
+            // Not all device variants lock when we go to sleep, so we need to explicitly lock the
+            // device. Note that pressSleepButton() above is redundant because the action also
+            // puts the device to sleep, but kept around for clarity.
+            InstrumentationRegistry.getInstrumentation().getUiAutomation().performGlobalAction(
+                    AccessibilityService.GLOBAL_ACTION_LOCK_SCREEN);
             waitForDisplayStateWithRetry(false /* displayOn */ );
             return this;
         }
diff --git a/tests/tests/nativehardware/jni/AHardwareBufferGLTest.cpp b/tests/tests/nativehardware/jni/AHardwareBufferGLTest.cpp
index a7d6535..96e39bc 100644
--- a/tests/tests/nativehardware/jni/AHardwareBufferGLTest.cpp
+++ b/tests/tests/nativehardware/jni/AHardwareBufferGLTest.cpp
@@ -273,6 +273,7 @@
 enum GoldenColor {
     kZero,  // all zero, i.e., transparent black
     kBlack,  // opaque black
+    kWhite,  // opaque white
     kRed,  // opaque red
     kGreen,  // opaque green
     kBlue,  // opaque blue
@@ -332,6 +333,7 @@
         case kGreen: golden_pixel[1] = 255; break;
         case kBlue: golden_pixel[2] = 255; break;
         case kZero: if (FormatHasAlpha(format)) golden_pixel[3] = 0; break;
+        case kWhite: golden_pixel[0] = 255; golden_pixel[1] = 255; golden_pixel[2] = 255; break;
         case kBlack: break;
         default: FAIL() << "Unrecognized golden pixel color";
     }
@@ -367,6 +369,7 @@
         case kGreen: golden_pixel[1] = 1.f; break;
         case kBlue: golden_pixel[2] = 1.f; break;
         case kZero: golden_pixel[3] = 0.f; break;
+        case kWhite: golden_pixel[0] = 1.f; golden_pixel[1] = 1.f; golden_pixel[2] = 1.f; break;
         case kBlack: break;
         default: FAIL() << "Unrecognized golden pixel color";
     }
@@ -692,6 +695,7 @@
     GLuint mTextures[2] = { 0, 0 };
     GLuint mBufferObjects[2] = { 0, 0 };
     GLuint mFramebuffers[2] = { 0, 0 };
+    GLint mMaxTextureUnits = 0;
 };
 
 void AHardwareBufferGLTest::SetUp() {
@@ -758,6 +762,7 @@
     ASSERT_TRUE(dot_pos > 0 && dot_pos < version.size() - 1);
     mGLVersion = (version[dot_pos - 1] - '0') * 10 + (version[dot_pos + 1] - '0');
     ASSERT_GE(mGLVersion, 20);
+    glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mMaxTextureUnits);
 }
 
 bool AHardwareBufferGLTest::SetUpBuffer(const AHardwareBuffer_Desc& desc) {
@@ -785,9 +790,17 @@
             mTexTarget = GL_TEXTURE_2D;
         }
     }
-    if (desc.format == GL_SRGB8_ALPHA8 && mGLVersion < 30) {
-        ALOGI("Test skipped: GL_SRGB8_ALPHA8 requires GL ES 3.0, found %d.%d",
-              mGLVersion / 10, mGLVersion % 10);
+    if ((desc.format == GL_RGB8 || desc.format == GL_RGBA8) &&
+        (desc.usage & AHARDWAREBUFFER_USAGE_GPU_COLOR_OUTPUT) &&
+        mGLVersion < 30 && !HasGLExtension("GL_OES_rgb8_rgba8")) {
+        ALOGI("Test skipped: GL_RGB8/GL_RGBA8 renderbuffers require GL ES 3.0 or "
+              "GL_OES_rgb8_rgba8, but neither were found.");
+        return false;
+    }
+    if (desc.format == GL_SRGB8_ALPHA8 && mGLVersion < 30 &&
+        !HasGLExtension("GL_EXT_sRGB")) {
+        ALOGI("Test skipped: GL_SRGB8_ALPHA8 requires GL ES 3.0 or GL_EXT_sRGB, "
+              "but neither were found.");
         return false;
     }
     if (desc.format == GL_RGB10_A2 && mGLVersion < 30) {
@@ -800,6 +813,20 @@
               mGLVersion / 10, mGLVersion % 10);
         return false;
     }
+    if (desc.format == GL_DEPTH_COMPONENT16 &&
+        (desc.usage & AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE) &&
+        mGLVersion < 30 && !HasGLExtension("GL_OES_depth_texture")) {
+        ALOGI("Test skipped: depth textures require GL ES 3.0 or "
+              "GL_OES_depth_texture, but neither were found.");
+        return false;
+    }
+    if (desc.format == GL_DEPTH24_STENCIL8 &&
+        (desc.usage & AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE) &&
+        mGLVersion < 30 && !HasGLExtension("GL_OES_packed_depth_stencil")) {
+        ALOGI("Test skipped: depth-stencil textures require GL ES 3.0 or "
+              "GL_OES_packed_depth_stencil, but neither were found.");
+        return false;
+    }
     // For control cases using GL formats, the test should be run in a single
     // context, without using AHardwareBuffer. This simplifies verifying that
     // the test behaves as expected even if the AHardwareBuffer format under
@@ -808,6 +835,8 @@
         mContextCount = 1;
         return true;
     }
+
+    // The code below will only execute if we are allocating a real AHardwareBuffer.
     if (use_srgb && !HasEGLExtension("EGL_EXT_image_gl_colorspace")) {
         ALOGI("Test skipped: sRGB hardware buffers require EGL_EXT_image_gl_colorspace");
         return false;
@@ -908,33 +937,50 @@
     glGenTextures(1, &texture);
     glActiveTexture(GL_TEXTURE0 + unit);
     glBindTexture(mTexTarget, texture);
+    // If the texture does not have mipmaps, set a filter that does not require them.
+    if (!(desc.usage & AHARDWAREBUFFER_USAGE_GPU_MIPMAP_COMPLETE)) {
+        glTexParameteri(mTexTarget, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+    }
     if (desc.stride & kGlFormat) {
         int levels = 1;
         if (desc.usage & AHARDWAREBUFFER_USAGE_GPU_MIPMAP_COMPLETE) {
             levels = MipLevelCount(desc.width, desc.height);
         }
-        // Stride is nonzero, so interpret desc.format as a GL format.
+        // kGlFormat is set in the stride field, so interpret desc.format as a GL format.
         if ((desc.usage & AHARDWAREBUFFER_USAGE_GPU_CUBE_MAP) ? desc.layers > 6 : desc.layers > 1) {
             glTexStorage3D(mTexTarget, levels, desc.format, desc.width, desc.height, desc.layers);
         } else if (mGLVersion >= 30) {
             glTexStorage2D(mTexTarget, levels, desc.format, desc.width, desc.height);
         } else {
-            GLenum format = 0, type = 0;
+            // Compatibility code for ES 2.0 goes here.
+            GLenum internal_format = 0, format = 0, type = 0;
             switch (desc.format) {
                 case GL_RGB8:
+                    internal_format = GL_RGB;
                     format = GL_RGB;
                     type = GL_UNSIGNED_BYTE;
                     break;
                 case GL_RGBA8:
+                    internal_format = GL_RGBA;
+                    format = GL_RGBA;
+                    type = GL_UNSIGNED_BYTE;
+                    break;
                 case GL_SRGB8_ALPHA8:
+                    // Available through GL_EXT_sRGB.
+                    internal_format = GL_SRGB_ALPHA_EXT;
                     format = GL_RGBA;
                     type = GL_UNSIGNED_BYTE;
                     break;
                 case GL_DEPTH_COMPONENT16:
+                    // Available through GL_OES_depth_texture.
+                    // Note that these are treated as luminance textures, not as red textures.
+                    internal_format = GL_DEPTH_COMPONENT;
                     format = GL_DEPTH_COMPONENT;
                     type = GL_UNSIGNED_SHORT;
                     break;
                 case GL_DEPTH24_STENCIL8:
+                    // Available through GL_OES_packed_depth_stencil.
+                    internal_format = GL_DEPTH_STENCIL_OES;
                     format = GL_DEPTH_STENCIL;
                     type = GL_UNSIGNED_INT_24_8;
                 default:
@@ -942,15 +988,23 @@
             }
             if (desc.usage & AHARDWAREBUFFER_USAGE_GPU_CUBE_MAP) {
                 for (int face = 0; face < 6; ++face) {
+                    uint32_t width = desc.width;
+                    uint32_t height = desc.height;
                     for (int level = 0; level < levels; ++level) {
-                        glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, level, desc.format,
-                                     desc.width, desc.height, 0, format, type, nullptr);
+                        glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, level, internal_format,
+                                     width, height, 0, format, type, nullptr);
+                        width /= 2;
+                        height /= 2;
                     }
                 }
             } else {
+                uint32_t width = desc.width;
+                uint32_t height = desc.height;
                 for (int level = 0; level < levels; ++level) {
-                    glTexImage2D(mTexTarget, level, desc.format, desc.width, desc.height, 0,
-                                format, type, nullptr);
+                    glTexImage2D(mTexTarget, level, internal_format, width, height, 0, format,
+                                 type, nullptr);
+                    width /= 2;
+                    height /= 2;
                 }
             }
         }
@@ -962,11 +1016,6 @@
             glEGLImageTargetTexture2DOES(mTexTarget, static_cast<GLeglImageOES>(mEGLImage));
         }
     }
-    // If the texture does not have mipmaps, set a filter that does not require them.
-    if (!(desc.usage & AHARDWAREBUFFER_USAGE_GPU_MIPMAP_COMPLETE)) {
-        glTexParameteri(mTexTarget, GL_TEXTURE_MAX_LEVEL, 0);
-        glTexParameteri(mTexTarget, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-    }
     ASSERT_EQ(GLenum{GL_NO_ERROR}, glGetError());
 }
 
@@ -1067,7 +1116,10 @@
 class BlobTest : public AHardwareBufferGLTest {
 public:
     bool SetUpBuffer(const AHardwareBuffer_Desc& desc) override {
-        if (!HasGLExtension("GL_EXT_external_buffer")) return false;
+        if (!HasGLExtension("GL_EXT_external_buffer")) {
+            ALOGI("Test skipped: GL_EXT_external_buffer not present");
+            return false;
+        }
         return AHardwareBufferGLTest::SetUpBuffer(desc);
     }
 };
@@ -1159,11 +1211,14 @@
 
 // Verifies that data written into a blob buffer from the GPU can be read on the CPU.
 TEST_P(BlobTest, GpuDataBufferCpuRead) {
+    if (mGLVersion < 31) {
+        ALOGI("Test skipped: shader storage buffer objects require ES 3.1+, found %d.%d",
+              mGLVersion / 10, mGLVersion % 10);
+        return;
+    }
     AHardwareBuffer_Desc desc = GetParam();
     desc.width = sizeof kQuadPositions;
     desc.usage = AHARDWAREBUFFER_USAGE_CPU_READ_RARELY | AHARDWAREBUFFER_USAGE_GPU_DATA_BUFFER;
-    // Shader storage buffer objects are only supported in OpenGL ES 3.1+
-    if (mGLVersion < 31) return;
     if (!SetUpBuffer(desc)) return;
 
     for (int i = 0; i < mContextCount; ++i) {
@@ -1354,7 +1409,7 @@
     if (!SetUpBuffer(desc)) return;
 
     // Bind the EGLImage to textures in both contexts.
-    const int kTextureUnit = 6;
+    const int kTextureUnit = 6 % mMaxTextureUnits;
     for (int i = 0; i < mContextCount; ++i) {
         MakeCurrent(i);
         SetUpTexture(desc, kTextureUnit);
@@ -1400,7 +1455,7 @@
     if (!SetUpBuffer(desc)) return;
 
     // Bind the EGLImage to textures in both contexts.
-    const int kTextureUnit = 1;
+    const int kTextureUnit = 1 % mMaxTextureUnits;
     for (int i = 0; i < mContextCount; ++i) {
         MakeCurrent(i);
         SetUpTexture(desc, kTextureUnit);
@@ -1440,6 +1495,11 @@
 }
 
 TEST_P(ColorTest, MipmapComplete) {
+    if (mGLVersion < 30) {
+        ALOGI("Test skipped: reading from nonzero level of a mipmap requires ES 3.0+, "
+              "found %d.%d", mGLVersion / 10, mGLVersion % 10);
+        return;
+    }
     const int kNumTiles = 8;
     AHardwareBuffer_Desc desc = GetParam();
     // Ensure that the checkerboard tiles have equal size at every level of the mipmap.
@@ -1451,7 +1511,7 @@
         AHARDWAREBUFFER_USAGE_GPU_MIPMAP_COMPLETE;
     if (!SetUpBuffer(desc)) return;
 
-    const int kTextureUnit = 7;
+    const int kTextureUnit = 7 % mMaxTextureUnits;
     for (int i = 0; i < mContextCount; ++i) {
         MakeCurrent(i);
         SetUpTexture(desc, kTextureUnit);
@@ -1492,7 +1552,7 @@
     desc.layers *= 6;
     if (!SetUpBuffer(desc)) return;
 
-    const int kTextureUnit = 4;
+    const int kTextureUnit = 4 % mMaxTextureUnits;
     for (int i = 0; i < mContextCount; ++i) {
         MakeCurrent(i);
         SetUpTexture(desc, kTextureUnit);
@@ -1532,6 +1592,11 @@
 }
 
 TEST_P(ColorTest, CubemapMipmaps) {
+    if (mGLVersion < 30) {
+        ALOGI("Test skipped: reading from nonzero level of a mipmap requires ES 3.0+, "
+              "found %d.%d", mGLVersion / 10, mGLVersion % 10);
+        return;
+    }
     const int kNumTiles = 8;
     AHardwareBuffer_Desc desc = GetParam();
     desc.usage =
@@ -1668,14 +1733,11 @@
 TEST_P(DepthTest, DepthCanBeSampled) {
     AHardwareBuffer_Desc desc = GetParam();
     desc.usage = AHARDWAREBUFFER_USAGE_GPU_COLOR_OUTPUT | AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE;
-    // ES 2.0 does not support depth textures. There is an extension OES_depth_texture, but it is
-    // incompatible with ES 3.x depth texture support.
-    if (mGLVersion < 30) return;
     if (!SetUpBuffer(desc)) return;
 
     // Bind the EGLImage to renderbuffers and framebuffers in both contexts.
     // The depth buffer is shared, but the color buffer is not.
-    const int kTextureUnit = 3;
+    const int kTextureUnit = 3 % mMaxTextureUnits;
     for (int i = 0; i < 2; ++i) {
         MakeCurrent(i);
         SetUpTexture(desc, kTextureUnit);
@@ -1704,12 +1766,13 @@
     EXPECT_EQ(GLenum{GL_NO_ERROR}, glGetError());
     glFinish();
 
-    // Check the rendered pixels. There should be a red square in the middle.
+    // Check the rendered pixels. There should be a square in the middle.
+    const GoldenColor kDepth = mGLVersion > 30 ? kRed : kWhite;
     std::vector<GoldenPixel> goldens{
-        {5, 35, kZero}, {15, 35, kZero}, {25, 35, kZero}, {35, 35, kZero},
-        {5, 25, kZero}, {15, 25, kRed},  {25, 25, kRed},  {35, 25, kZero},
-        {5, 15, kZero}, {15, 15, kRed},  {25, 15, kRed},  {35, 15, kZero},
-        {5,  5, kZero}, {15,  5, kZero}, {25, 5,  kZero}, {35, 5,  kZero},
+        {5, 35, kZero}, {15, 35, kZero},  {25, 35, kZero},  {35, 35, kZero},
+        {5, 25, kZero}, {15, 25, kDepth}, {25, 25, kDepth}, {35, 25, kZero},
+        {5, 15, kZero}, {15, 15, kDepth}, {25, 15, kDepth}, {35, 15, kZero},
+        {5,  5, kZero}, {15,  5, kZero},  {25, 5,  kZero},  {35, 5,  kZero},
     };
     CheckGoldenPixels(goldens, GL_RGBA8);
 }
@@ -1724,7 +1787,7 @@
     desc.layers *= 6;
     if (!SetUpBuffer(desc)) return;
 
-    const int kTextureUnit = 9;
+    const int kTextureUnit = 9 % mMaxTextureUnits;
     for (int i = 0; i < mContextCount; ++i) {
         MakeCurrent(i);
         SetUpTexture(desc, kTextureUnit);
@@ -1755,6 +1818,7 @@
         SetUpProgram(kVertexShader, kCubeMapFragmentShader, kQuadPositions, 0.5f, kTextureUnit);
     }
     SetUpFramebuffer(40, 40, 0, kRenderbuffer);
+    const GoldenColor kDepth = mGLVersion > 30 ? kRed : kWhite;
     for (int i = 0; i < 6; ++i) {
         float face_vector[3] = {0.f, 0.f, 0.f};
         face_vector[i / 2] = (i % 2) ? -1.f : 1.f;
@@ -1765,8 +1829,8 @@
 
         std::vector<GoldenPixel> goldens{
             {5, 35, kZero}, {15, 35, kZero},  {25, 35, kZero},  {35, 35, kZero},
-            {5, 25, kZero}, {15, 25, kBlack}, {25, 25, kRed},   {35, 25, kZero},
-            {5, 15, kZero}, {15, 15, kRed},   {25, 15, kBlack}, {35, 15, kZero},
+            {5, 25, kZero}, {15, 25, kBlack}, {25, 25, kDepth}, {35, 25, kZero},
+            {5, 15, kZero}, {15, 15, kDepth}, {25, 15, kBlack}, {35, 15, kZero},
             {5, 5,  kZero}, {15, 5,  kZero},  {25, 5,  kZero},  {35, 5,  kZero},
         };
         CheckGoldenPixels(goldens, GL_RGBA8);
@@ -1866,7 +1930,7 @@
     if (!kPureStencil && mGLVersion < 31) return;
     if (!SetUpBuffer(desc)) return;
 
-    const int kTextureUnit = 8;
+    const int kTextureUnit = 8 % mMaxTextureUnits;
     for (int i = 0; i < mContextCount; ++i) {
         MakeCurrent(i);
         SetUpTexture(desc, kTextureUnit);
diff --git a/tests/tests/systemui/src/android/systemui/cts/LightBarTests.java b/tests/tests/systemui/src/android/systemui/cts/LightBarTests.java
index 2c5d468..fc7e70f 100644
--- a/tests/tests/systemui/src/android/systemui/cts/LightBarTests.java
+++ b/tests/tests/systemui/src/android/systemui/cts/LightBarTests.java
@@ -56,7 +56,7 @@
      * Color may be slightly off-spec when resources are resized for lower densities. Use this error
      * margin to accommodate for that when comparing colors.
      */
-    private static final int COLOR_COMPONENT_ERROR_MARGIN = 10;
+    private static final int COLOR_COMPONENT_ERROR_MARGIN = 20;
 
     private final String NOTIFICATION_TAG = "TEST_TAG";
     private final String NOTIFICATION_CHANNEL_ID = "test_channel";
@@ -235,7 +235,7 @@
         float eps = 0.005f;
 
         for (int c : pixels) {
-            if (c == background) {
+            if (isColorSame(c, background)) {
                 s.backgroundPixels++;
                 continue;
             }