Snap for 7272189 from 89d5d9fee5adcf8bf90bbfb311080259aa64daeb to mainline-media-swcodec-release

Change-Id: Ic82be2aef18a6ec7921d414d3e86a58bd2091cd1
diff --git a/hostsidetests/securitybulletin/securityPatch/CVE-2020-0224/Android.bp b/hostsidetests/securitybulletin/securityPatch/CVE-2020-0224/Android.bp
deleted file mode 100644
index 084a1fe..0000000
--- a/hostsidetests/securitybulletin/securityPatch/CVE-2020-0224/Android.bp
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * 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.
- *
- */
-
-cc_test {
-    name: "CVE-2020-0224",
-    defaults: ["cts_hostsidetests_securitybulletin_defaults"],
-    shared_libs: [
-        "libpac",
-    ],
-    srcs: [
-        "poc.cpp",
-    ],
-}
diff --git a/hostsidetests/securitybulletin/securityPatch/CVE-2020-0224/poc.cpp b/hostsidetests/securitybulletin/securityPatch/CVE-2020-0224/poc.cpp
deleted file mode 100644
index de62221..0000000
--- a/hostsidetests/securitybulletin/securityPatch/CVE-2020-0224/poc.cpp
+++ /dev/null
@@ -1,60 +0,0 @@
-/**
- * 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.
- */
-
-#include <codecvt>
-#include <fstream>
-#include "../includes/common.h"
-#include <proxy_resolver_v8_wrapper.h>
-
-using namespace std;
-
-void poc(char* raw) {
-    ProxyResolverV8Handle* handle = ProxyResolverV8Handle_new();
-    string u8Script(raw);
-    u16string u16Script =
-            wstring_convert<codecvt_utf8_utf16<char16_t>, char16_t> { }
-                    .from_bytes(u8Script);
-
-    ProxyResolverV8Handle_SetPacScript(handle, u16Script.data());
-    const char16_t* spec = u"", *host = u"";
-    ProxyResolverV8Handle_GetProxyForURL(handle, spec, host);
-    ProxyResolverV8Handle_delete(handle);
-}
-
-int main(int argc, char **argv) {
-    if (argc != 2) {
-        return EXIT_FAILURE;
-    }
-
-    ifstream stream;
-    stream.open(argv[1]);
-    if (stream.rdstate() != ifstream::goodbit) {
-        return EXIT_FAILURE;
-    }
-
-    stream.seekg(0, ios::end);
-    size_t size = stream.tellg();
-    stream.seekg(0);
-    char* raw = (char*) calloc(size + 1, sizeof(char));
-    stream.read(raw, size);
-    time_t currentTime = start_timer();
-    while (timer_active(currentTime)) {
-        poc(raw);
-    }
-
-    free(raw);
-    return EXIT_SUCCESS;
-}
diff --git a/hostsidetests/securitybulletin/src/android/security/cts/CVE_2020_0224.java b/hostsidetests/securitybulletin/src/android/security/cts/CVE_2020_0224.java
index b02eeea..4cd94c9 100644
--- a/hostsidetests/securitybulletin/src/android/security/cts/CVE_2020_0224.java
+++ b/hostsidetests/securitybulletin/src/android/security/cts/CVE_2020_0224.java
@@ -33,16 +33,10 @@
     @SecurityTest(minPatchLevel = "2020-07")
     @Test
     public void testPocCVE_2020_0224() throws Exception {
-        String inputFiles[] = {"cve_2020_0224.pac"};
-        String binaryName = "CVE-2020-0224";
-        String signals[] = {CrashUtils.SIGSEGV, CrashUtils.SIGBUS, CrashUtils.SIGABRT};
-        AdbUtils.pocConfig testConfig = new AdbUtils.pocConfig(binaryName, getDevice());
-        testConfig.config = new CrashUtils.Config().setProcessPatterns(binaryName);
-        testConfig.config.setSignals(signals);
-        testConfig.config.checkMinAddress(false);
-        testConfig.arguments = AdbUtils.TMP_PATH + inputFiles[0];
-        testConfig.inputFiles = Arrays.asList(inputFiles);
-        testConfig.inputFilesDestination = AdbUtils.TMP_PATH;
-        AdbUtils.runPocAssertNoCrashesNotVulnerable(testConfig);
+        AdbUtils.runProxyAutoConfig("cve_2020_0224", getDevice());
+        AdbUtils.assertNoCrashes(getDevice(), new CrashUtils.Config()
+                .setProcessPatterns("pacrunner")
+                .checkMinAddress(false)
+                .appendSignals(CrashUtils.SIGABRT));
     }
 }
diff --git a/tests/app/app/src/android/app/stubs/LocalForegroundService.java b/tests/app/app/src/android/app/stubs/LocalForegroundService.java
index 3051a18..90a4097 100644
--- a/tests/app/app/src/android/app/stubs/LocalForegroundService.java
+++ b/tests/app/app/src/android/app/stubs/LocalForegroundService.java
@@ -32,7 +32,7 @@
 
     private static final String TAG = "LocalForegroundService";
     protected static final String EXTRA_COMMAND = "LocalForegroundService.command";
-    private static final String NOTIFICATION_CHANNEL_ID = "cts/" + TAG;
+    public static final String NOTIFICATION_CHANNEL_ID = "cts/" + TAG;
     public static String ACTION_START_FGS_RESULT =
             "android.app.stubs.LocalForegroundService.RESULT";
 
diff --git a/tests/app/src/android/app/cts/ServiceTest.java b/tests/app/src/android/app/cts/ServiceTest.java
index 792ef5d..d2e0776 100644
--- a/tests/app/src/android/app/cts/ServiceTest.java
+++ b/tests/app/src/android/app/cts/ServiceTest.java
@@ -1105,6 +1105,31 @@
         assertNoNotification(2);
     }
 
+    public void testForegroundService_notificationChannelDeletion() throws Exception {
+        NotificationManager noMan = mContext.getSystemService(NotificationManager.class);
+
+        // Start service as foreground - it should show notification #1
+        mExpectedServiceState = STATE_START_1;
+        startForegroundService(LocalForegroundService.COMMAND_START_FOREGROUND);
+        waitForResultOrThrow(DELAY, "service to start first time");
+        assertNotification(1, LocalForegroundService.getNotificationTitle(1));
+
+        try {
+            final String channel = LocalForegroundService.NOTIFICATION_CHANNEL_ID;
+            noMan.deleteNotificationChannel(channel);
+            fail("Deleting FGS notification channel did not throw");
+        } catch (SecurityException se) {
+            // Expected outcome, i.e. success case
+        } catch (Exception e) {
+            fail("Deleting FGS notification threw unexpected failure " + e);
+        }
+
+        mExpectedServiceState = STATE_DESTROY;
+        mContext.stopService(mLocalForegroundService);
+        waitForResultOrThrow(DELAY, "service to be destroyed");
+
+    }
+
     class TestSendCallback implements PendingIntent.OnFinished {
         public volatile int result = -1;
 
diff --git a/tests/framework/base/windowmanager/Android.mk b/tests/framework/base/windowmanager/Android.mk
index ef6a95e..39d0812 100644
--- a/tests/framework/base/windowmanager/Android.mk
+++ b/tests/framework/base/windowmanager/Android.mk
@@ -44,7 +44,7 @@
     CtsMockInputMethodLib \
     metrics-helper-lib \
 
-LOCAL_COMPATIBILITY_SUITE := cts vts10 general-tests
+LOCAL_COMPATIBILITY_SUITE := cts vts10 general-tests sts
 
 LOCAL_SDK_VERSION := test_current
 
diff --git a/tests/framework/base/windowmanager/alertwindowapp/Android.bp b/tests/framework/base/windowmanager/alertwindowapp/Android.bp
index 07069de..c8245da 100644
--- a/tests/framework/base/windowmanager/alertwindowapp/Android.bp
+++ b/tests/framework/base/windowmanager/alertwindowapp/Android.bp
@@ -29,5 +29,6 @@
         "cts",
         "vts10",
         "general-tests",
+        "sts",
     ],
 }
diff --git a/tests/framework/base/windowmanager/alertwindowappsdk25/Android.bp b/tests/framework/base/windowmanager/alertwindowappsdk25/Android.bp
index e7cbcdb..fd6d943 100644
--- a/tests/framework/base/windowmanager/alertwindowappsdk25/Android.bp
+++ b/tests/framework/base/windowmanager/alertwindowappsdk25/Android.bp
@@ -31,5 +31,6 @@
         "cts",
         "vts10",
         "general-tests",
+        "sts",
     ],
 }
diff --git a/tests/framework/base/windowmanager/alertwindowservice/Android.bp b/tests/framework/base/windowmanager/alertwindowservice/Android.bp
index 58d8688..6aee4e4 100644
--- a/tests/framework/base/windowmanager/alertwindowservice/Android.bp
+++ b/tests/framework/base/windowmanager/alertwindowservice/Android.bp
@@ -27,6 +27,7 @@
         "cts",
         "vts10",
         "general-tests",
+        "sts",
     ],
 
     dex_preopt: {
diff --git a/tests/framework/base/windowmanager/app/Android.bp b/tests/framework/base/windowmanager/app/Android.bp
index b12f93b..3512924 100644
--- a/tests/framework/base/windowmanager/app/Android.bp
+++ b/tests/framework/base/windowmanager/app/Android.bp
@@ -33,5 +33,6 @@
         "cts",
         "vts10",
         "general-tests",
+        "sts",
     ],
 }
diff --git a/tests/framework/base/windowmanager/app27/Android.bp b/tests/framework/base/windowmanager/app27/Android.bp
index 6ddf919..79d2d22 100644
--- a/tests/framework/base/windowmanager/app27/Android.bp
+++ b/tests/framework/base/windowmanager/app27/Android.bp
@@ -26,5 +26,6 @@
         "cts",
         "vts10",
         "general-tests",
+        "sts",
     ],
 }
diff --git a/tests/framework/base/windowmanager/appAShareUid/Android.bp b/tests/framework/base/windowmanager/appAShareUid/Android.bp
index 57adfd6..052f829 100644
--- a/tests/framework/base/windowmanager/appAShareUid/Android.bp
+++ b/tests/framework/base/windowmanager/appAShareUid/Android.bp
@@ -26,5 +26,6 @@
         "cts",
         "vts10",
         "general-tests",
+        "sts",
     ],
 }
diff --git a/tests/framework/base/windowmanager/appBShareUid/Android.bp b/tests/framework/base/windowmanager/appBShareUid/Android.bp
index ec15e80..8fe4775 100644
--- a/tests/framework/base/windowmanager/appBShareUid/Android.bp
+++ b/tests/framework/base/windowmanager/appBShareUid/Android.bp
@@ -26,5 +26,6 @@
         "cts",
         "vts10",
         "general-tests",
+        "sts",
     ],
 }
diff --git a/tests/framework/base/windowmanager/appDeprecatedSdk/Android.bp b/tests/framework/base/windowmanager/appDeprecatedSdk/Android.bp
index c83b44f..8582bf1 100644
--- a/tests/framework/base/windowmanager/appDeprecatedSdk/Android.bp
+++ b/tests/framework/base/windowmanager/appDeprecatedSdk/Android.bp
@@ -26,5 +26,6 @@
         "cts",
         "vts10",
         "general-tests",
+        "sts",
     ],
 }
diff --git a/tests/framework/base/windowmanager/appDisplaySize/Android.bp b/tests/framework/base/windowmanager/appDisplaySize/Android.bp
index 819a9bf..d492d7b 100644
--- a/tests/framework/base/windowmanager/appDisplaySize/Android.bp
+++ b/tests/framework/base/windowmanager/appDisplaySize/Android.bp
@@ -26,5 +26,6 @@
         "cts",
         "vts10",
         "general-tests",
+        "sts",
     ],
 }
diff --git a/tests/framework/base/windowmanager/appPrereleaseSdk/Android.bp b/tests/framework/base/windowmanager/appPrereleaseSdk/Android.bp
index d110d19..6f5d5e4 100644
--- a/tests/framework/base/windowmanager/appPrereleaseSdk/Android.bp
+++ b/tests/framework/base/windowmanager/appPrereleaseSdk/Android.bp
@@ -24,5 +24,6 @@
         "cts",
         "vts10",
         "general-tests",
+        "sts",
     ],
 }
diff --git a/tests/framework/base/windowmanager/appProfileable/Android.bp b/tests/framework/base/windowmanager/appProfileable/Android.bp
index cd54094..2dcd954 100644
--- a/tests/framework/base/windowmanager/appProfileable/Android.bp
+++ b/tests/framework/base/windowmanager/appProfileable/Android.bp
@@ -26,5 +26,6 @@
         "cts",
         "vts10",
         "general-tests",
+        "sts"
     ],
 }
diff --git a/tests/framework/base/windowmanager/appSecondUid/Android.bp b/tests/framework/base/windowmanager/appSecondUid/Android.bp
index 5f44f5c..692f73b 100644
--- a/tests/framework/base/windowmanager/appSecondUid/Android.bp
+++ b/tests/framework/base/windowmanager/appSecondUid/Android.bp
@@ -26,5 +26,6 @@
         "cts",
         "vts10",
         "general-tests",
+        "sts",
     ],
 }
diff --git a/tests/framework/base/windowmanager/appThirdUid/Android.bp b/tests/framework/base/windowmanager/appThirdUid/Android.bp
index 08a878c..22bab9d 100644
--- a/tests/framework/base/windowmanager/appThirdUid/Android.bp
+++ b/tests/framework/base/windowmanager/appThirdUid/Android.bp
@@ -26,5 +26,6 @@
         "cts",
         "vts10",
         "general-tests",
+        "sts",
     ],
 }
diff --git a/tests/framework/base/windowmanager/dndsourceapp/Android.bp b/tests/framework/base/windowmanager/dndsourceapp/Android.bp
index 7abd478..9a1463e 100644
--- a/tests/framework/base/windowmanager/dndsourceapp/Android.bp
+++ b/tests/framework/base/windowmanager/dndsourceapp/Android.bp
@@ -26,5 +26,6 @@
         "cts",
         "vts10",
         "general-tests",
+        "sts",
     ],
 }
diff --git a/tests/framework/base/windowmanager/dndtargetapp/Android.bp b/tests/framework/base/windowmanager/dndtargetapp/Android.bp
index 00b4055..0a14121 100644
--- a/tests/framework/base/windowmanager/dndtargetapp/Android.bp
+++ b/tests/framework/base/windowmanager/dndtargetapp/Android.bp
@@ -24,6 +24,7 @@
         "cts",
         "vts10",
         "general-tests",
+        "sts",
     ],
 
     static_libs: ["cts-wm-app-base"],
diff --git a/tests/framework/base/windowmanager/dndtargetappsdk23/Android.bp b/tests/framework/base/windowmanager/dndtargetappsdk23/Android.bp
index 13dbca2..4420670 100644
--- a/tests/framework/base/windowmanager/dndtargetappsdk23/Android.bp
+++ b/tests/framework/base/windowmanager/dndtargetappsdk23/Android.bp
@@ -24,6 +24,7 @@
         "cts",
         "vts10",
         "general-tests",
+        "sts",
     ],
 
     static_libs: ["cts-wm-app-base"],
diff --git a/tests/framework/base/windowmanager/src/android/server/wm/PinnedStackTests.java b/tests/framework/base/windowmanager/src/android/server/wm/PinnedStackTests.java
index 98e5ff5..6e19de2 100644
--- a/tests/framework/base/windowmanager/src/android/server/wm/PinnedStackTests.java
+++ b/tests/framework/base/windowmanager/src/android/server/wm/PinnedStackTests.java
@@ -91,6 +91,7 @@
 import android.os.Handler;
 import android.os.Looper;
 import android.platform.test.annotations.Presubmit;
+import android.platform.test.annotations.SecurityTest;
 import android.provider.Settings;
 import android.server.wm.CommandSession.ActivityCallback;
 import android.server.wm.CommandSession.SizeInfo;
@@ -278,6 +279,7 @@
     }
 
     @Test
+    @SecurityTest(minPatchLevel="2021-03")
     public void testEnterPipWithTinyMinimalSize() throws Exception {
         // Launch a PiP activity with minimal size specified and smaller than allowed minimum
         launchActivity(PIP_ACTIVITY_WITH_TINY_MINIMAL_SIZE, EXTRA_ENTER_PIP, "true");
diff --git a/tests/framework/base/windowmanager/translucentapp/Android.bp b/tests/framework/base/windowmanager/translucentapp/Android.bp
index c551c29..3a19970 100644
--- a/tests/framework/base/windowmanager/translucentapp/Android.bp
+++ b/tests/framework/base/windowmanager/translucentapp/Android.bp
@@ -31,5 +31,6 @@
         "cts",
         "vts10",
         "general-tests",
+        "sts",
     ],
 }
diff --git a/tests/framework/base/windowmanager/translucentappsdk26/Android.bp b/tests/framework/base/windowmanager/translucentappsdk26/Android.bp
index 7c8d0d8..4ec800b 100644
--- a/tests/framework/base/windowmanager/translucentappsdk26/Android.bp
+++ b/tests/framework/base/windowmanager/translucentappsdk26/Android.bp
@@ -29,5 +29,6 @@
         "cts",
         "vts10",
         "general-tests",
+        "sts",
     ],
 }
diff --git a/tests/inputmethod/mockime/Android.bp b/tests/inputmethod/mockime/Android.bp
index 2283541..6159a6c 100644
--- a/tests/inputmethod/mockime/Android.bp
+++ b/tests/inputmethod/mockime/Android.bp
@@ -43,6 +43,7 @@
         "vts10",
         "general-tests",
         "mts",
+        "sts",
     ],
     static_libs: [
         "androidx.annotation_annotation",
diff --git a/tests/tests/media/src/android/media/cts/DecoderTestXheAac.java b/tests/tests/media/src/android/media/cts/DecoderTestXheAac.java
index 8536f30..dbcba7f 100755
--- a/tests/tests/media/src/android/media/cts/DecoderTestXheAac.java
+++ b/tests/tests/media/src/android/media/cts/DecoderTestXheAac.java
@@ -33,8 +33,8 @@
 import android.media.cts.DecoderTestAacDrc.DrcParams;
 import android.media.cts.R;
 import android.os.Build;
-import android.util.Log;
 import android.os.Bundle;
+import android.util.Log;
 
 import androidx.test.InstrumentationRegistry;
 
@@ -567,6 +567,13 @@
     @Test
     public void testDecodeUsacSyncSampleSeekingM4a() throws Exception {
         Log.v(TAG, "START testDecodeUsacSyncSampleSeekingM4a");
+        if(!sIsAndroidRAndAbove) {
+            // The fix for b/158471477 was released in mainline release 300802800
+            // See https://android-build.googleplex.com/builds/treetop/googleplex-android-review/11990700
+            final int MIN_VERSION = 300802800;
+            TestUtils.assumeMainlineModuleAtLeast("com.google.android.media.swcodec", MIN_VERSION);
+            TestUtils.assumeMainlineModuleAtLeast("com.google.android.media", MIN_VERSION);
+        }
 
         assertTrue("No AAC decoder found", sAacDecoderNames.size() > 0);
 
diff --git a/tests/tests/media/src/android/media/cts/MediaMetadataRetrieverTest.java b/tests/tests/media/src/android/media/cts/MediaMetadataRetrieverTest.java
index 48208d9..98acf0b 100644
--- a/tests/tests/media/src/android/media/cts/MediaMetadataRetrieverTest.java
+++ b/tests/tests/media/src/android/media/cts/MediaMetadataRetrieverTest.java
@@ -345,6 +345,11 @@
     }
 
     public void testID3v240ExtHeader() {
+        if(!ApiLevelUtil.isAtLeast(Build.VERSION_CODES.R)) {
+            // The fix for b/154357105 was released in mainline release 30.09.007.01
+            // See https://android-build.googleplex.com/builds/treetop/googleplex-android-review/11174063
+            TestUtils.assumeMainlineModuleAtLeast("com.google.android.media", 300900701);
+        }
         setDataSourceFd(R.raw.sinesweepid3v24ext);
         assertEquals("Mime type was other than expected",
                 "audio/mpeg",
diff --git a/tests/tests/media/src/android/media/cts/TestUtils.java b/tests/tests/media/src/android/media/cts/TestUtils.java
index 093cc8c..fb8212f 100644
--- a/tests/tests/media/src/android/media/cts/TestUtils.java
+++ b/tests/tests/media/src/android/media/cts/TestUtils.java
@@ -16,21 +16,21 @@
 
 package android.media.cts;
 
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static android.content.pm.PackageManager.MATCH_APEX;
+
+import static org.junit.Assume.assumeNoException;
+import static org.junit.Assume.assumeTrue;
 
 import android.content.Context;
-import android.media.session.MediaSessionManager;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
 import android.os.Bundle;
-import android.os.Handler;
-import android.os.Looper;
 
-import java.io.FileDescriptor;
-import java.util.ArrayList;
-import java.util.List;
+import androidx.test.core.app.ApplicationProvider;
+
+import org.junit.AssumptionViolatedException;
+
 import java.util.Objects;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
 
 /**
  * Utilities for tests.
@@ -66,6 +66,34 @@
         return true;
     }
 
+    /**
+     * Checks {@code module} is at least {@code minVersion}
+     *
+     * The tests are skipped by throwing a {@link AssumptionViolatedException}.  CTS test runners
+     * will report this as a {@code ASSUMPTION_FAILED}.
+     *
+     * @param module     the apex module name
+     * @param minVersion the minimum version
+     * @throws AssumptionViolatedException if module.minVersion < minVersion
+     */
+    static void assumeMainlineModuleAtLeast(String module, long minVersion) {
+        Context context = ApplicationProvider.getApplicationContext();
+        PackageInfo info;
+        try {
+            info = context.getPackageManager().getPackageInfo(module,
+                    MATCH_APEX);
+            long actualVersion = info.getLongVersionCode();
+            assumeTrue("Assumed Module  " + module + " minVersion " + actualVersion + " >= "
+                            + minVersion,
+                    actualVersion >= minVersion);
+        } catch (PackageManager.NameNotFoundException e) {
+            assumeNoException(e);
+        }
+    }
+
+    private TestUtils() {
+    }
+
     public static class Monitor {
         private int mNumSignal;