Merge "Remove app/Android.mk"
diff --git a/hostsidetests/accounts/test-apps/Android.mk b/hostsidetests/accounts/test-apps/Android.mk
deleted file mode 100644
index 0d4c793..0000000
--- a/hostsidetests/accounts/test-apps/Android.mk
+++ /dev/null
@@ -1,24 +0,0 @@
-# Copyright (C) 2019 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.
-
-LOCAL_PATH := $(call my-dir)
-
-include $(CLEAR_VARS)
-
-# tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts general-tests
-
-# Build the test APKs using their own makefiles
-include $(call all-makefiles-under,$(LOCAL_PATH))
-
diff --git a/hostsidetests/appsecurity/test-apps/EncryptionApp/src/com/android/cts/encryptionapp/EncryptionAppTest.java b/hostsidetests/appsecurity/test-apps/EncryptionApp/src/com/android/cts/encryptionapp/EncryptionAppTest.java
index 2088caa..342348c 100644
--- a/hostsidetests/appsecurity/test-apps/EncryptionApp/src/com/android/cts/encryptionapp/EncryptionAppTest.java
+++ b/hostsidetests/appsecurity/test-apps/EncryptionApp/src/com/android/cts/encryptionapp/EncryptionAppTest.java
@@ -115,7 +115,8 @@
         // Set a PIN for this user
         mDevice.executeShellCommand("settings put global require_password_to_decrypt 0");
         mDevice.executeShellCommand("locksettings set-disabled false");
-        mDevice.executeShellCommand("locksettings set-pin 12345");
+        String output = mDevice.executeShellCommand("locksettings set-pin 12345");
+        assertTrue("set-pin failed. Output: " + output, output.contains("12345"));
     }
 
     public void testTearDown() throws Exception {
diff --git a/hostsidetests/appsecurity/test-apps/SplitApp/libs/armeabi-v7a/Android.bp b/hostsidetests/appsecurity/test-apps/SplitApp/libs/armeabi-v7a/Android.bp
new file mode 100644
index 0000000..a46f8b4
--- /dev/null
+++ b/hostsidetests/appsecurity/test-apps/SplitApp/libs/armeabi-v7a/Android.bp
@@ -0,0 +1,37 @@
+//
+// Copyright (C) 2014 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 {
+    // See: http://go/android-license-faq
+    default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+android_test_helper_app {
+    name: "CtsSplitApp_armeabi-v7a",
+    defaults: ["cts_support_defaults"],
+    sdk_version: "current",
+    java_resource_dirs: ["raw"],
+    // tag this module as a cts test artifact
+    test_suites: [
+        "cts",
+        "general-tests",
+    ],
+    certificate: ":cts-testkey1",
+    aaptflags: [
+        "--version-code 100",
+        "--replace-version",
+    ],
+}
diff --git a/hostsidetests/appsecurity/test-apps/SplitApp/libs/armeabi-v7a/Android.mk b/hostsidetests/appsecurity/test-apps/SplitApp/libs/armeabi-v7a/Android.mk
deleted file mode 100644
index 9e27161..0000000
--- a/hostsidetests/appsecurity/test-apps/SplitApp/libs/armeabi-v7a/Android.mk
+++ /dev/null
@@ -1,34 +0,0 @@
-#
-# Copyright (C) 2014 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.
-#
-
-LOCAL_PATH := $(call my-dir)
-
-include $(CLEAR_VARS)
-
-LOCAL_PACKAGE_NAME := CtsSplitApp_armeabi-v7a
-LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0
-LOCAL_LICENSE_CONDITIONS := notice
-LOCAL_SDK_VERSION := current
-
-LOCAL_JAVA_RESOURCE_DIRS := raw
-
-# tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts general-tests
-
-LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/cts-testkey1
-LOCAL_AAPT_FLAGS := --version-code 100 --replace-version
-
-include $(BUILD_CTS_SUPPORT_PACKAGE)
diff --git a/hostsidetests/appsecurity/test-apps/SplitApp/libs/armeabi/Android.bp b/hostsidetests/appsecurity/test-apps/SplitApp/libs/armeabi/Android.bp
new file mode 100644
index 0000000..9b9335c
--- /dev/null
+++ b/hostsidetests/appsecurity/test-apps/SplitApp/libs/armeabi/Android.bp
@@ -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 {
+    // See: http://go/android-license-faq
+    default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+android_test {
+    name: "CtsSplitApp_armeabi",
+    defaults: ["cts_support_defaults"],
+    sdk_version: "current",
+    java_resource_dirs: ["raw"],
+    // tag this module as a cts test artifact
+    test_suites: [
+        "cts",
+        "general-tests",
+    ],
+    certificate: ":cts-testkey1",
+    aaptflags: [
+        "--version-code 100",
+        "--replace-version",
+    ],
+}
diff --git a/hostsidetests/appsecurity/test-apps/SplitApp/libs/armeabi/Android.mk b/hostsidetests/appsecurity/test-apps/SplitApp/libs/armeabi/Android.mk
deleted file mode 100644
index 8da02fd..0000000
--- a/hostsidetests/appsecurity/test-apps/SplitApp/libs/armeabi/Android.mk
+++ /dev/null
@@ -1,34 +0,0 @@
-#
-# Copyright (C) 2014 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.
-#
-
-LOCAL_PATH := $(call my-dir)
-
-include $(CLEAR_VARS)
-
-LOCAL_PACKAGE_NAME := CtsSplitApp_armeabi
-LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0
-LOCAL_LICENSE_CONDITIONS := notice
-LOCAL_SDK_VERSION := current
-
-LOCAL_JAVA_RESOURCE_DIRS := raw
-
-# tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts general-tests
-
-LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/cts-testkey1
-LOCAL_AAPT_FLAGS := --version-code 100 --replace-version
-
-include $(BUILD_CTS_SUPPORT_PACKAGE)
diff --git a/hostsidetests/appsecurity/test-apps/SplitApp/libs/mips/Android.bp b/hostsidetests/appsecurity/test-apps/SplitApp/libs/mips/Android.bp
new file mode 100644
index 0000000..6b48066
--- /dev/null
+++ b/hostsidetests/appsecurity/test-apps/SplitApp/libs/mips/Android.bp
@@ -0,0 +1,37 @@
+//
+// Copyright (C) 2014 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 {
+    // See: http://go/android-license-faq
+    default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+android_test_helper_app {
+    name: "CtsSplitApp_mips",
+    defaults: ["cts_support_defaults"],
+    sdk_version: "current",
+    java_resource_dirs: ["raw"],
+    // tag this module as a cts test artifact
+    test_suites: [
+        "cts",
+        "general-tests",
+    ],
+    certificate: ":cts-testkey1",
+    aaptflags: [
+        "--version-code 100",
+        "--replace-version",
+    ],
+}
diff --git a/hostsidetests/appsecurity/test-apps/SplitApp/libs/mips/Android.mk b/hostsidetests/appsecurity/test-apps/SplitApp/libs/mips/Android.mk
deleted file mode 100644
index 533525b..0000000
--- a/hostsidetests/appsecurity/test-apps/SplitApp/libs/mips/Android.mk
+++ /dev/null
@@ -1,34 +0,0 @@
-#
-# Copyright (C) 2014 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.
-#
-
-LOCAL_PATH := $(call my-dir)
-
-include $(CLEAR_VARS)
-
-LOCAL_PACKAGE_NAME := CtsSplitApp_mips
-LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0
-LOCAL_LICENSE_CONDITIONS := notice
-LOCAL_SDK_VERSION := current
-
-LOCAL_JAVA_RESOURCE_DIRS := raw
-
-# tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts general-tests
-
-LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/cts-testkey1
-LOCAL_AAPT_FLAGS := --version-code 100 --replace-version
-
-include $(BUILD_CTS_SUPPORT_PACKAGE)
diff --git a/hostsidetests/appsecurity/test-apps/SplitApp/libs/mips64/Android.bp b/hostsidetests/appsecurity/test-apps/SplitApp/libs/mips64/Android.bp
new file mode 100644
index 0000000..8de81d9
--- /dev/null
+++ b/hostsidetests/appsecurity/test-apps/SplitApp/libs/mips64/Android.bp
@@ -0,0 +1,37 @@
+//
+// Copyright (C) 2014 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 {
+    // See: http://go/android-license-faq
+    default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+android_test_helper_app {
+    name: "CtsSplitApp_mips64",
+    defaults: ["cts_support_defaults"],
+    sdk_version: "current",
+    java_resource_dirs: ["raw"],
+    // tag this module as a cts test artifact
+    test_suites: [
+        "cts",
+        "general-tests",
+    ],
+    certificate: ":cts-testkey1",
+    aaptflags: [
+        "--version-code 100",
+        "--replace-version",
+    ],
+}
diff --git a/hostsidetests/appsecurity/test-apps/SplitApp/libs/mips64/Android.mk b/hostsidetests/appsecurity/test-apps/SplitApp/libs/mips64/Android.mk
deleted file mode 100644
index 64ec09a..0000000
--- a/hostsidetests/appsecurity/test-apps/SplitApp/libs/mips64/Android.mk
+++ /dev/null
@@ -1,34 +0,0 @@
-#
-# Copyright (C) 2014 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.
-#
-
-LOCAL_PATH := $(call my-dir)
-
-include $(CLEAR_VARS)
-
-LOCAL_PACKAGE_NAME := CtsSplitApp_mips64
-LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0
-LOCAL_LICENSE_CONDITIONS := notice
-LOCAL_SDK_VERSION := current
-
-LOCAL_JAVA_RESOURCE_DIRS := raw
-
-# tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts general-tests
-
-LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/cts-testkey1
-LOCAL_AAPT_FLAGS := --version-code 100 --replace-version
-
-include $(BUILD_CTS_SUPPORT_PACKAGE)
diff --git a/hostsidetests/appsecurity/test-apps/SplitApp/libs/x86/Android.bp b/hostsidetests/appsecurity/test-apps/SplitApp/libs/x86/Android.bp
new file mode 100644
index 0000000..f761bff
--- /dev/null
+++ b/hostsidetests/appsecurity/test-apps/SplitApp/libs/x86/Android.bp
@@ -0,0 +1,37 @@
+//
+// Copyright (C) 2014 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 {
+    // See: http://go/android-license-faq
+    default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+android_test_helper_app {
+    name: "CtsSplitApp_x86",
+    defaults: ["cts_support_defaults"],
+    sdk_version: "current",
+    java_resource_dirs: ["raw"],
+    // tag this module as a cts test artifact
+    test_suites: [
+        "cts",
+        "general-tests",
+    ],
+    certificate: ":cts-testkey1",
+    aaptflags: [
+        "--version-code 100",
+        "--replace-version",
+    ],
+}
diff --git a/hostsidetests/appsecurity/test-apps/SplitApp/libs/x86/Android.mk b/hostsidetests/appsecurity/test-apps/SplitApp/libs/x86/Android.mk
deleted file mode 100644
index e6a6cf0b..0000000
--- a/hostsidetests/appsecurity/test-apps/SplitApp/libs/x86/Android.mk
+++ /dev/null
@@ -1,34 +0,0 @@
-#
-# Copyright (C) 2014 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.
-#
-
-LOCAL_PATH := $(call my-dir)
-
-include $(CLEAR_VARS)
-
-LOCAL_PACKAGE_NAME := CtsSplitApp_x86
-LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0
-LOCAL_LICENSE_CONDITIONS := notice
-LOCAL_SDK_VERSION := current
-
-LOCAL_JAVA_RESOURCE_DIRS := raw
-
-# tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts general-tests
-
-LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/cts-testkey1
-LOCAL_AAPT_FLAGS := --version-code 100 --replace-version
-
-include $(BUILD_CTS_SUPPORT_PACKAGE)
diff --git a/hostsidetests/appsecurity/test-apps/SplitApp/libs/x86_64/Android.bp b/hostsidetests/appsecurity/test-apps/SplitApp/libs/x86_64/Android.bp
new file mode 100644
index 0000000..55217c3
--- /dev/null
+++ b/hostsidetests/appsecurity/test-apps/SplitApp/libs/x86_64/Android.bp
@@ -0,0 +1,37 @@
+//
+// Copyright (C) 2014 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 {
+    // See: http://go/android-license-faq
+    default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+android_test_helper_app {
+    name: "CtsSplitApp_x86_64",
+    defaults: ["cts_support_defaults"],
+    sdk_version: "current",
+    java_resource_dirs: ["raw"],
+    // tag this module as a cts test artifact
+    test_suites: [
+        "cts",
+        "general-tests",
+    ],
+    certificate: ":cts-testkey1",
+    aaptflags: [
+        "--version-code 100",
+        "--replace-version",
+    ],
+}
diff --git a/hostsidetests/appsecurity/test-apps/SplitApp/libs/x86_64/Android.mk b/hostsidetests/appsecurity/test-apps/SplitApp/libs/x86_64/Android.mk
deleted file mode 100644
index 456ef11..0000000
--- a/hostsidetests/appsecurity/test-apps/SplitApp/libs/x86_64/Android.mk
+++ /dev/null
@@ -1,34 +0,0 @@
-#
-# Copyright (C) 2014 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.
-#
-
-LOCAL_PATH := $(call my-dir)
-
-include $(CLEAR_VARS)
-
-LOCAL_PACKAGE_NAME := CtsSplitApp_x86_64
-LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0
-LOCAL_LICENSE_CONDITIONS := notice
-LOCAL_SDK_VERSION := current
-
-LOCAL_JAVA_RESOURCE_DIRS := raw
-
-# tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts general-tests
-
-LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/cts-testkey1
-LOCAL_AAPT_FLAGS := --version-code 100 --replace-version
-
-include $(BUILD_CTS_SUPPORT_PACKAGE)
diff --git a/hostsidetests/securitybulletin/Android.mk b/hostsidetests/securitybulletin/Android.mk
deleted file mode 100644
index bbf61ce..0000000
--- a/hostsidetests/securitybulletin/Android.mk
+++ /dev/null
@@ -1,15 +0,0 @@
-# Copyright (C) 2014 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 $(call all-subdir-makefiles)
diff --git a/tests/app/src/android/app/cts/ActivityManagerApi29Test.java b/tests/app/src/android/app/cts/ActivityManagerApi29Test.java
index 28611c5..f0c5769 100644
--- a/tests/app/src/android/app/cts/ActivityManagerApi29Test.java
+++ b/tests/app/src/android/app/cts/ActivityManagerApi29Test.java
@@ -17,7 +17,6 @@
 
 import static android.Manifest.permission.ACCESS_COARSE_LOCATION;
 import static android.app.ActivityManager.PROCESS_CAPABILITY_ALL;
-import static android.app.ActivityManager.PROCESS_CAPABILITY_FOREGROUND_LOCATION;
 import static android.app.ActivityManager.PROCESS_CAPABILITY_NONE;
 import static android.app.AppOpsManager.MODE_ALLOWED;
 import static android.app.AppOpsManager.MODE_FOREGROUND;
@@ -47,6 +46,7 @@
 import android.permission.cts.PermissionUtils;
 import android.provider.DeviceConfig;
 import android.provider.Settings;
+import android.support.test.uiautomator.UiDevice;
 
 import androidx.test.InstrumentationRegistry;
 import androidx.test.runner.AndroidJUnit4;
@@ -128,6 +128,9 @@
             sAppOps.resetHistoryParameters(); }
         );
         mUidWatcher = new WatchUidRunner(sInstrumentation, sUid, WAITFOR_MSEC);
+        // Press home key to ensure stopAppSwitches is called so the grace period of
+        // the background start will be ignored if there's any.
+        UiDevice.getInstance(sInstrumentation).pressHome();
     }
 
     @After
diff --git a/tests/app/src/android/app/cts/ActivityManagerFgsBgStartTest.java b/tests/app/src/android/app/cts/ActivityManagerFgsBgStartTest.java
index c982cd6..a2ee858 100644
--- a/tests/app/src/android/app/cts/ActivityManagerFgsBgStartTest.java
+++ b/tests/app/src/android/app/cts/ActivityManagerFgsBgStartTest.java
@@ -28,6 +28,7 @@
 import android.content.pm.ApplicationInfo;
 import android.content.pm.ServiceInfo;
 import android.os.Bundle;
+import android.support.test.uiautomator.UiDevice;
 import android.test.InstrumentationTestCase;
 
 public class ActivityManagerFgsBgStartTest extends InstrumentationTestCase {
@@ -55,6 +56,9 @@
         CtsAppTestUtils.makeUidIdle(mInstrumentation, PACKAGE_NAME_APP1);
         CtsAppTestUtils.makeUidIdle(mInstrumentation, PACKAGE_NAME_APP2);
         CtsAppTestUtils.turnScreenOn(mInstrumentation, mContext);
+        // Press home key to ensure stopAppSwitches is called so the grace period of
+        // the background start will be ignored if there's any.
+        UiDevice.getInstance(mInstrumentation).pressHome();
     }
 
     @Override
diff --git a/tests/framework/base/windowmanager/src/android/server/wm/AnrTests.java b/tests/framework/base/windowmanager/src/android/server/wm/AnrTests.java
index effa21f..6bb7d44 100644
--- a/tests/framework/base/windowmanager/src/android/server/wm/AnrTests.java
+++ b/tests/framework/base/windowmanager/src/android/server/wm/AnrTests.java
@@ -125,9 +125,12 @@
 
         // TODO(b/143566069) investigate why we need multiple taps on display to trigger anr.
         mWmState.computeState();
-        tapOnDisplayCenterAsync(DEFAULT_DISPLAY);
+        // Tap on the UnresponsiveActivity
+        final WindowManagerState.ActivityTask unresponsiveActivityTask =
+                mWmState.getTaskByActivity(UNRESPONSIVE_ACTIVITY);
+        tapOnStackCenterAsync(unresponsiveActivityTask);
         SystemClock.sleep(1000);
-        tapOnDisplayCenterAsync(DEFAULT_DISPLAY);
+        tapOnStackCenterAsync(unresponsiveActivityTask);
 
         clickCloseAppOnAnrDialog();
         assertEventLogsContainsAnr(UnresponsiveActivity.PROCESS_NAME);
@@ -143,9 +146,12 @@
 
         // TODO(b/143566069) investigate why we need multiple taps on display to trigger anr.
         mWmState.computeState();
-        tapOnDisplayCenterAsync(DEFAULT_DISPLAY);
+        // Tap on the HostActivity
+        final WindowManagerState.ActivityTask hostActivityTask =
+                mWmState.getTaskByActivity(HOST_ACTIVITY);
+        tapOnStackCenterAsync(hostActivityTask);
         SystemClock.sleep(1000);
-        tapOnDisplayCenterAsync(DEFAULT_DISPLAY);
+        tapOnStackCenterAsync(hostActivityTask);
 
         clickCloseAppOnAnrDialog();
         assertEventLogsContainsAnr(RenderService.PROCESS_NAME);
diff --git a/tests/framework/base/windowmanager/src/android/server/wm/MultiDisplayPolicyTests.java b/tests/framework/base/windowmanager/src/android/server/wm/MultiDisplayPolicyTests.java
index 3584353..cea851d 100644
--- a/tests/framework/base/windowmanager/src/android/server/wm/MultiDisplayPolicyTests.java
+++ b/tests/framework/base/windowmanager/src/android/server/wm/MultiDisplayPolicyTests.java
@@ -564,7 +564,9 @@
         waitAndAssertActivityStateOnDisplay(TEST_ACTIVITY, STATE_RESUMED, newDisplay.mId,
                 "Activity launched on secondary display must be resumed");
 
-        tapOnDisplayCenter(DEFAULT_DISPLAY);
+        // Tap on task center to switch focus between displays. Using task center instead of
+        // display center to cover the multi window scenario.
+        tapOnStackCenter(mWmState.getTaskByActivity(VIRTUAL_DISPLAY_ACTIVITY));
 
         waitAndAssertTopResumedActivity(VIRTUAL_DISPLAY_ACTIVITY, DEFAULT_DISPLAY,
                 "Top activity must be on the primary display");
@@ -618,7 +620,9 @@
         assertBothDisplaysHaveResumedActivities(pair(DEFAULT_DISPLAY, RESIZEABLE_ACTIVITY),
                 pair(newDisplay.mId, TEST_ACTIVITY));
 
-        tapOnDisplayCenter(DEFAULT_DISPLAY);
+        // Tap on task center to switch focus between displays. Using task center instead of
+        // display center to cover the multi window scenario.
+        tapOnStackCenter(mWmState.getTaskByActivity(RESIZEABLE_ACTIVITY));
 
         // Check that the activity on the primary display is the topmost resumed
         waitAndAssertTopResumedActivity(RESIZEABLE_ACTIVITY, DEFAULT_DISPLAY,
@@ -669,7 +673,9 @@
         mWmState.assertFocusedAppOnDisplay("Activity on second display must be focused.",
                 VIRTUAL_DISPLAY_ACTIVITY, newDisplay.mId);
 
-        tapOnDisplayCenter(DEFAULT_DISPLAY);
+        // Tap on task center to switch focus between displays. Using task center instead of
+        // display center to cover the multi window scenario.
+        tapOnStackCenter(mWmState.getTaskByActivity(TEST_ACTIVITY));
 
         waitAndAssertTopResumedActivity(TEST_ACTIVITY, DEFAULT_DISPLAY,
                 "Activity should be top resumed when tapped.");
@@ -860,7 +866,9 @@
         waitAndAssertTopResumedActivity(SDK_27_TEST_ACTIVITY, newDisplay.mId,
                 "Activity launched on secondary display must be resumed and focused");
 
-        tapOnDisplayCenter(DEFAULT_DISPLAY);
+        // Tap on task center to switch focus between displays. Using task center instead of
+        // display center to cover the multi window scenario.
+        tapOnStackCenter(mWmState.getTaskByActivity(SDK_27_LAUNCHING_ACTIVITY));
         waitAndAssertTopResumedActivity(SDK_27_LAUNCHING_ACTIVITY, DEFAULT_DISPLAY,
                 "Activity launched on default display must be resumed and focused");
         assertEquals("There must be only one resumed activity in the package.", 1,
diff --git a/tests/framework/base/windowmanager/util/src/android/server/wm/ActivityManagerTestBase.java b/tests/framework/base/windowmanager/util/src/android/server/wm/ActivityManagerTestBase.java
index 9e11ebb..5341ed7 100644
--- a/tests/framework/base/windowmanager/util/src/android/server/wm/ActivityManagerTestBase.java
+++ b/tests/framework/base/windowmanager/util/src/android/server/wm/ActivityManagerTestBase.java
@@ -693,10 +693,20 @@
         tapOnDisplaySync(tapX, tapY, displayId);
     }
 
+    protected void tapOnCenterAsync(Rect bounds, int displayId) {
+        final int tapX = bounds.left + bounds.width() / 2;
+        final int tapY = bounds.top + bounds.height() / 2;
+        tapOnDisplay(tapX, tapY, displayId, false /* sync*/);
+    }
+
     protected void tapOnStackCenter(WindowManagerState.ActivityTask stack) {
         tapOnCenter(stack.getBounds(), stack.mDisplayId);
     }
 
+    protected  void tapOnStackCenterAsync(WindowManagerState.ActivityTask stack) {
+        tapOnCenterAsync(stack.getBounds(), stack.mDisplayId);
+    }
+
     protected void tapOnDisplayCenter(int displayId) {
         final Rect bounds = mWmState.getDisplay(displayId).getDisplayRect();
         tapOnDisplaySync(bounds.centerX(), bounds.centerY(), displayId);
diff --git a/tests/libcore/okhttp/Android.bp b/tests/libcore/okhttp/Android.bp
index 7b20ee2..7f55497 100644
--- a/tests/libcore/okhttp/Android.bp
+++ b/tests/libcore/okhttp/Android.bp
@@ -16,8 +16,8 @@
     default_applicable_licenses: ["Android-Apache-2.0"],
 }
 
-android_test {
-    name: "CtsLibcoreOkHttpTestCases",
+java_defaults {
+    name: "libcore_okhttp_test_cases_defaults",
     defaults: ["cts_support_defaults"],
     platform_apis: true,
     min_sdk_version: "29",
@@ -40,10 +40,28 @@
     // Include both the 32 and 64 bit versions of libjavacoretests,
     // where applicable.
     compile_multilib: "both",
+}
+
+// Tests used in CTS and in Conscrypt MTS.
+android_test {
+    name: "CtsLibcoreOkHttpTestCases",
+    defaults: ["libcore_okhttp_test_cases_defaults"],
     // Tag this module as a cts test artifact
     test_suites: [
         "cts",
         "general-tests",
         "mts",
     ],
+  test_config: "CtsLibcoreOkHttpTestCases.xml"
+}
+
+// Tests used in ART MTS.
+android_test {
+    name: "MtsLibcoreOkHttpTestCases",
+    defaults: ["libcore_okhttp_test_cases_defaults"],
+    test_suites: [
+        "general-tests",
+        "mts-art",
+    ],
+  test_config: "MtsLibcoreOkHttpTestCases.xml"
 }
diff --git a/tests/libcore/okhttp/AndroidTest.xml b/tests/libcore/okhttp/CtsLibcoreOkHttpTestCases.xml
similarity index 100%
rename from tests/libcore/okhttp/AndroidTest.xml
rename to tests/libcore/okhttp/CtsLibcoreOkHttpTestCases.xml
diff --git a/tests/libcore/okhttp/MtsLibcoreOkHttpTestCases.xml b/tests/libcore/okhttp/MtsLibcoreOkHttpTestCases.xml
new file mode 100644
index 0000000..8219e38c
--- /dev/null
+++ b/tests/libcore/okhttp/MtsLibcoreOkHttpTestCases.xml
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+<configuration description="Config for MTS Libcore OkHttp test cases">
+    <option name="config-descriptor:metadata" key="component" value="libcore" />
+    <option name="config-descriptor:metadata" key="parameter" value="multi_abi" />
+    <!-- Test is eligible to run on Android Multiuser users other than SYSTEM.
+         See source.android.com/devices/tech/admin/multi-user#user_types -->
+    <option name="config-descriptor:metadata" key="parameter" value="secondary_user" />
+    <option name="config-descriptor:metadata" key="parameter" value="not_instant_app" />
+    <target_preparer class="com.android.tradefed.targetprep.RunCommandTargetPreparer">
+        <!-- This MTS test module requires wifi, ensure wifi is on -->
+        <option name="run-command" value="settings put global wifi_on 1" />
+        <option name="run-command" value="svc wifi enable" />
+        <option name="run-command" value="mkdir -p /data/local/tmp/ctslibcore/java.io.tmpdir" />
+        <option name="run-command" value="mkdir -p /data/local/tmp/ctslibcore/user.home" />
+        <option name="teardown-command" value="rm -rf /data/local/tmp/ctslibcore" />
+    </target_preparer>
+    <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
+        <option name="cleanup-apks" value="true" />
+        <!-- this has just the instrumentation which acts as the tests we want to run -->
+        <option name="test-file-name" value="MtsLibcoreOkHttpTestCases.apk" />
+    </target_preparer>
+    <test class="com.android.compatibility.testtype.LibcoreTest" >
+        <option name="package" value="android.libcore.cts.okhttp" />
+        <option name="instrumentation-arg" key="filter"
+                value="com.android.cts.core.runner.ExpectationBasedFilter" />
+        <option name="core-expectation" value="/knownfailures.txt" />
+        <option name="runtime-hint" value="15m"/>
+        <!-- 20x default timeout of 600sec -->
+        <option name="shell-timeout" value="12000000"/>
+        <option name="hidden-api-checks" value="false"/>
+    </test>
+
+    <object type="module_controller" class="com.android.tradefed.testtype.suite.module.TestFailureModuleController">
+        <option name="screenshot-on-failure" value="false" />
+    </object>
+
+    <!-- When this test is run in a Mainline context (e.g. with `mts-tradefed`), only enable it if
+         one of the Mainline modules below is present on the device used for testing. -->
+    <object type="module_controller" class="com.android.tradefed.testtype.suite.module.MainlineTestModuleController">
+        <!-- ART Mainline Module (internal version). -->
+        <option name="mainline-module-package-name" value="com.google.android.art" />
+        <!-- ART Mainline Module (external (AOSP) version). -->
+        <option name="mainline-module-package-name" value="com.android.art" />
+    </object>
+</configuration>
diff --git a/tests/tests/binder_ndk/src/android/binder/cts/JavaClientTest.java b/tests/tests/binder_ndk/src/android/binder/cts/JavaClientTest.java
index d380647..3b5db4c 100644
--- a/tests/tests/binder_ndk/src/android/binder/cts/JavaClientTest.java
+++ b/tests/tests/binder_ndk/src/android/binder/cts/JavaClientTest.java
@@ -675,6 +675,27 @@
             Assert.assertArrayEquals(baz.d, newBaz.d);
         }
     }
+
+    @Test
+    public void testGetInterfaceVersion() throws RemoteException {
+        ICompatTest compatTest = ICompatTest.Stub.asInterface(mInterface.getICompatTest());
+        if (mShouldBeOld) {
+            assertEquals(1, compatTest.getInterfaceVersion());
+        } else {
+            assertEquals(3, compatTest.getInterfaceVersion());
+        }
+    }
+
+    @Test
+    public void testGetInterfaceHash() throws RemoteException {
+        ICompatTest compatTest = ICompatTest.Stub.asInterface(mInterface.getICompatTest());
+        if (mShouldBeOld) {
+            assertEquals("b663b681b3e0d66f9b5428c2f23365031b7d4ba0", compatTest.getInterfaceHash());
+        } else {
+            assertEquals("notfrozen", compatTest.getInterfaceHash());
+        }
+    }
+
     @Test
     public void testRenameFoo() throws RemoteException {
         Foo foo = new Foo();
diff --git a/tests/tests/media/src/android/media/cts/MediaCodecTest.java b/tests/tests/media/src/android/media/cts/MediaCodecTest.java
index e764ac5..b86302c 100644
--- a/tests/tests/media/src/android/media/cts/MediaCodecTest.java
+++ b/tests/tests/media/src/android/media/cts/MediaCodecTest.java
@@ -2660,6 +2660,7 @@
             for (String mime: info.getSupportedTypes()) {
                 CodecCapabilities caps = info.getCapabilitiesForType(mime);
                 boolean isVideo = (caps.getVideoCapabilities() != null);
+                boolean isAudio = (caps.getAudioCapabilities() != null);
 
                 MediaCodec codec = null;
                 MediaFormat format = null;
@@ -2677,7 +2678,7 @@
                         format.setInteger(MediaFormat.KEY_BIT_RATE, minBitrate);
                         format.setInteger(MediaFormat.KEY_FRAME_RATE, minFrameRate);
                         format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, IFRAME_INTERVAL);
-                    } else {
+                    } else if(isAudio){
                         AudioCapabilities acaps = caps.getAudioCapabilities();
                         int minSampleRate = acaps.getSupportedSampleRateRanges()[0].getLower();
                         int minChannelCount = 1;
@@ -2685,11 +2686,13 @@
                         format = MediaFormat.createAudioFormat(mime, minSampleRate, minChannelCount);
                         format.setInteger(MediaFormat.KEY_BIT_RATE, minBitrate);
                     }
-                    format.setInteger(MediaFormat.KEY_PREPEND_HEADER_TO_SYNC_FRAMES, 1);
 
-                    codec.configure(format, null /* surface */, null /* crypto */,
+                    if (isVideo || isAudio) {
+                        format.setInteger(MediaFormat.KEY_PREPEND_HEADER_TO_SYNC_FRAMES, 1);
+
+                        codec.configure(format, null /* surface */, null /* crypto */,
                             isEncoder ? codec.CONFIGURE_FLAG_ENCODE : 0);
-
+                    }
                     if (isVideo && isEncoder) {
                         Log.i(TAG, info.getName() + " supports KEY_PREPEND_HEADER_TO_SYNC_FRAMES");
                     } else {
diff --git a/tests/tests/os/src/android/os/cts/BuildTest.java b/tests/tests/os/src/android/os/cts/BuildTest.java
index 8049ca1..2ea90b6 100644
--- a/tests/tests/os/src/android/os/cts/BuildTest.java
+++ b/tests/tests/os/src/android/os/cts/BuildTest.java
@@ -285,6 +285,8 @@
         // CUR_DEVELOPMENT must be larger than any released version.
         Field[] fields = Build.VERSION_CODES.class.getDeclaredFields();
         List<String> codenames = Arrays.asList(ACTIVE_CODENAMES);
+        // Make the codenames uppercase to match the field names.
+        codenames.replaceAll(String::toUpperCase);
         for (Field field : fields) {
             if (field.getType().equals(int.class) && Modifier.isStatic(field.getModifiers())) {
                 String fieldName = field.getName();
diff --git a/tests/tests/permission2/res/raw/android_manifest.xml b/tests/tests/permission2/res/raw/android_manifest.xml
index 8695968..4136494 100644
--- a/tests/tests/permission2/res/raw/android_manifest.xml
+++ b/tests/tests/permission2/res/raw/android_manifest.xml
@@ -3187,6 +3187,13 @@
     <permission android:name="android.permission.TRIGGER_SHELL_BUGREPORT"
         android:protectionLevel="signature" />
 
+    <!-- Allows an application to trigger profcollect report upload via shell.
+        <p>Not for use by third-party applications.
+        @hide
+    -->
+    <permission android:name="android.permission.TRIGGER_SHELL_PROFCOLLECT_UPLOAD"
+        android:protectionLevel="signature" />
+
     <!-- Allows an application to be the status bar.  Currently used only by SystemUI.apk
     @hide -->
     // TODO: remove telephony once decouple settings activity from phone process
diff --git a/tests/tests/simphonebookprovider/src/android/provider/cts/simphonebook/SimPhonebookContract_SimRecordsMultiSimTest.java b/tests/tests/simphonebookprovider/src/android/provider/cts/simphonebook/SimPhonebookContract_SimRecordsMultiSimTest.java
index df7a20b..0782b88 100644
--- a/tests/tests/simphonebookprovider/src/android/provider/cts/simphonebook/SimPhonebookContract_SimRecordsMultiSimTest.java
+++ b/tests/tests/simphonebookprovider/src/android/provider/cts/simphonebook/SimPhonebookContract_SimRecordsMultiSimTest.java
@@ -88,7 +88,7 @@
              Cursor sim2Cursor = query(SimRecords.getContentUri(mSubscriptionId2, EF_ADN),
                      projection)) {
             assertThat(sim1Cursor).hasCount(1);
-            assertThat(sim1Cursor).hasSingleRow("Name1 Adn1", 5550101);
+            assertThat(sim1Cursor).hasSingleRow(mSubscriptionId1, EF_ADN, "Name1 Adn1", "5550101");
 
             assertThat(sim2Cursor).hasCount(3);
             assertThat(sim2Cursor).atRow(0)
@@ -119,8 +119,8 @@
         };
         try (Cursor sim1Cursor = query(uriSim1, projection);
              Cursor sim2Cursor = query(uriSim2, projection)) {
-            assertThat(sim1Cursor).hasSingleRow(mSubscriptionId1, "Name Sim1");
-            assertThat(sim2Cursor).hasSingleRow(mSubscriptionId2, "Name Sim2");
+            assertThat(sim1Cursor).hasSingleRow(mSubscriptionId1, "5550101");
+            assertThat(sim2Cursor).hasSingleRow(mSubscriptionId2, "5550102");
         }
     }
 
diff --git a/tests/tests/vcn/src/android/net/vcn/cts/VcnManagerTest.java b/tests/tests/vcn/src/android/net/vcn/cts/VcnManagerTest.java
index e4f224f..cf63243 100644
--- a/tests/tests/vcn/src/android/net/vcn/cts/VcnManagerTest.java
+++ b/tests/tests/vcn/src/android/net/vcn/cts/VcnManagerTest.java
@@ -462,6 +462,7 @@
             @NonNull Network cellNetwork,
             @NonNull VcnTestNetworkCallback cellNetworkCb)
             throws Exception {
+        cellNetworkCb.waitForAvailable();
         mVcnManager.setVcnConfig(subGrp, buildTestModeVcnConfig());
 
         // Wait until the cell Network is lost (due to losing NOT_VCN_MANAGED) to wait for
diff --git a/tests/video/src/android/video/cts/CodecDecoderPerformanceTest.java b/tests/video/src/android/video/cts/CodecDecoderPerformanceTest.java
index 3460b16..93c4431 100644
--- a/tests/video/src/android/video/cts/CodecDecoderPerformanceTest.java
+++ b/tests/video/src/android/video/cts/CodecDecoderPerformanceTest.java
@@ -55,7 +55,8 @@
                 "crowd_run_1280x720_30fps_hevc.mp4",
                 "crowd_run_1920x1080_30fps_hevc.mp4",
                 "crowd_run_3840x2160_30fps_hevc.mp4",
-                "crowd_run_7680x4320_30fps_hevc.mp4",
+                // TODO (b/194721211) Enable 8k tests
+                //"crowd_run_7680x4320_30fps_hevc.mp4",
                 // VP8
                 "crowd_run_720x480_30fps_vp8.webm",
                 "crowd_run_1280x720_30fps_vp8.webm",
@@ -66,19 +67,22 @@
                 "crowd_run_1280x720_30fps_vp9.webm",
                 "crowd_run_1920x1080_30fps_vp9.webm",
                 "crowd_run_3840x2160_30fps_vp9.webm",
-                "crowd_run_7680x4320_30fps_vp9.webm",
+                // TODO (b/194721211) Enable 8k tests
+                //"crowd_run_7680x4320_30fps_vp9.webm",
                 // AV1
                 "crowd_run_720x480_30fps_av1.mp4",
                 "crowd_run_1280x720_30fps_av1.mp4",
                 "crowd_run_1920x1080_30fps_av1.mp4",
                 "crowd_run_3840x2160_30fps_av1.mp4",
-                "crowd_run_7680x4320_30fps_av1.mp4",
+                // TODO (b/194721211) Enable 8k tests
+                //"crowd_run_7680x4320_30fps_av1.mp4",
                 // MPEG-2
                 "crowd_run_720x480_30fps_mpeg2.mp4",
                 "crowd_run_1280x720_30fps_mpeg2.mp4",
                 "crowd_run_1920x1080_30fps_mpeg2.mp4",
                 "crowd_run_3840x2160_30fps_mpeg2.mp4",
-                "crowd_run_7680x4320_30fps_mpeg2.mp4",
+                // TODO (b/194721211) Enable 8k tests
+                //"crowd_run_7680x4320_30fps_mpeg2.mp4",
         };
         // Prepares the params list combining with supported Hardware decoders, key priority
         // and scaling factor.
diff --git a/tests/video/src/android/video/cts/CodecEncoderPerformanceTest.java b/tests/video/src/android/video/cts/CodecEncoderPerformanceTest.java
index 89b6949..973e2dd 100644
--- a/tests/video/src/android/video/cts/CodecEncoderPerformanceTest.java
+++ b/tests/video/src/android/video/cts/CodecEncoderPerformanceTest.java
@@ -58,7 +58,8 @@
                 {"crowd_run_1280x720_30fps_avc.mp4", 4000000},
                 {"crowd_run_1920x1080_30fps_avc.mp4", 8000000},
                 {"crowd_run_3840x2160_30fps_hevc.mp4", 20000000},
-                {"crowd_run_7680x4320_30fps_hevc.mp4", 40000000},
+                // TODO (b/194721211) Enable 8k tests
+                //{"crowd_run_7680x4320_30fps_hevc.mp4", 40000000},
         });
         // Prepares the params list with the supported Hardware decoder, encoders in the device
         // combined with the key priority and scaling factor