Snap for 8512216 from 096d171c7d4aae5abffeb11545579c915a16db5f to tm-frc-permission-release
Change-Id: Icda4a61c203878ac34b9bb152c12013343a6700c
diff --git a/tests/packagemanagerlocal/Android.bp b/tests/packagemanagerlocal/Android.bp
new file mode 100644
index 0000000..c1f3115
--- /dev/null
+++ b/tests/packagemanagerlocal/Android.bp
@@ -0,0 +1,39 @@
+// Copyright (C) 2022 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 {
+ default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+android_test {
+ name: "CtsRootPackageManagerLocalTests",
+ defaults: ["cts_defaults"],
+ static_libs: [
+ "androidx.test.core",
+ "androidx.test.rules",
+ "platform-test-annotations",
+ "services.core",
+ "truth-prebuilt",
+ ],
+ libs: [
+ "android.test.runner",
+ "android.test.base",
+ ],
+ srcs: ["src/**/*.java"],
+ test_suites: [
+ "cts_root",
+ "general-tests",
+ ],
+ sdk_version: "test_current",
+}
diff --git a/tests/packagemanagerlocal/AndroidManifest.xml b/tests/packagemanagerlocal/AndroidManifest.xml
new file mode 100644
index 0000000..9f8c2f7
--- /dev/null
+++ b/tests/packagemanagerlocal/AndroidManifest.xml
@@ -0,0 +1,28 @@
+<!--
+ ~ Copyright (C) 2022 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.
+ -->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="android.packagemanagerlocal.cts_root" >
+
+ <application>
+ <uses-library android:name="android.test.runner" />
+ </application>
+
+ <instrumentation android:name="androidx.test.runner.AndroidJUnitRunner"
+ android:targetPackage="android"
+ android:label="PackageManagerLocal CTS root tests"/>
+
+</manifest>
diff --git a/tests/packagemanagerlocal/AndroidTest.xml b/tests/packagemanagerlocal/AndroidTest.xml
new file mode 100644
index 0000000..0095b11
--- /dev/null
+++ b/tests/packagemanagerlocal/AndroidTest.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Copyright (C) 2022 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="Runs PackageManagerLocal CTS root tests">
+ <option name="test-suite-tag" value="apct" />
+ <option name="test-suite-tag" value="apct-instrumentation" />
+
+ <target_preparer class="com.android.tradefed.targetprep.RootTargetPreparer"/>
+
+ <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
+ <option name="cleanup-apks" value="true"/>
+ <option name="test-file-name" value="CtsRootPackageManagerLocalTests.apk"/>
+ </target_preparer>
+
+ <!-- Restart to clear test code from system server -->
+ <target_preparer class="com.android.tradefed.targetprep.DeviceCleaner">
+ <option name="cleanup-action" value="REBOOT" />
+ </target_preparer>
+
+ <test class="com.android.tradefed.testtype.AndroidJUnitTest">
+ <option name="package" value="android.packagemanagerlocal.cts_root"/>
+ <option name="runner" value="androidx.test.runner.AndroidJUnitRunner" />
+ <option name="restart" value="false" />
+ </test>
+</configuration>
diff --git a/tests/packagemanagerlocal/OWNERS b/tests/packagemanagerlocal/OWNERS
new file mode 100644
index 0000000..4e5fe55
--- /dev/null
+++ b/tests/packagemanagerlocal/OWNERS
@@ -0,0 +1,3 @@
+# Bug component: 36137
+alexbuy@google.com
+patb@google.com
diff --git a/tests/packagemanagerlocal/TEST_MAPPING b/tests/packagemanagerlocal/TEST_MAPPING
new file mode 100644
index 0000000..54b32af
--- /dev/null
+++ b/tests/packagemanagerlocal/TEST_MAPPING
@@ -0,0 +1,7 @@
+{
+ "presubmit": [
+ {
+ "name": "CtsRootPackageManagerLocalTests"
+ }
+ ]
+}
diff --git a/tests/packagemanagerlocal/src/android/packagemanagerlocal/cts_root/PackageManagerLocalTest.java b/tests/packagemanagerlocal/src/android/packagemanagerlocal/cts_root/PackageManagerLocalTest.java
new file mode 100644
index 0000000..9ba383b
--- /dev/null
+++ b/tests/packagemanagerlocal/src/android/packagemanagerlocal/cts_root/PackageManagerLocalTest.java
@@ -0,0 +1,132 @@
+/*
+ * Copyright (C) 2022 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 android.packagemanagerlocal.cts_root;
+
+import static com.google.common.truth.Truth.assertThat;
+import static com.google.common.truth.Truth.assertWithMessage;
+
+import androidx.test.runner.AndroidJUnit4;
+
+import com.android.server.LocalManagerRegistry;
+import com.android.server.pm.PackageManagerLocal;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.io.File;
+import java.nio.file.Files;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+@RunWith(AndroidJUnit4.class)
+public final class PackageManagerLocalTest {
+ private static final String TAG = "PackageManagerLocalTest";
+
+ private PackageManagerLocal mPackageManagerLocal;
+
+ @Before
+ public void setup() {
+ mPackageManagerLocal = LocalManagerRegistry.getManager(PackageManagerLocal.class);
+ }
+
+ @Test
+ public void testPackageManagerLocal_ReconcileSdkData_DifferentStorageFlags() throws Exception {
+ final String volumeUuid = null;
+ final String packageName = "android.packagemanagerlocal.test";
+ final List<String> subDirNames = Arrays.asList("one", "two@random");
+ final int userId = 0;
+ final int appId = 10000;
+ final int previousAppId = -1;
+ final String seInfo = "default";
+
+ // There are two flags: FLAG_STORAGE_CE and FLAG_STORAGE_DE. So total of 4 combination
+ // to test.
+ for (int currentFlag = 0; currentFlag < 4; currentFlag++) {
+ final String errorMsg = "Failed for flag: " + currentFlag;
+
+ File cePackageDirFile = new File("/data/misc_ce/0/sdksandbox/" + packageName);
+ File dePackageDirFile = new File("/data/misc_de/0/sdksandbox/" + packageName);
+
+ try {
+ mPackageManagerLocal.reconcileSdkData(volumeUuid, packageName, subDirNames, userId,
+ appId, previousAppId, seInfo, currentFlag);
+
+ // Verify that sdk data directories have been created in the desired location
+ boolean hasCeFlag = (currentFlag & PackageManagerLocal.FLAG_STORAGE_CE) != 0;
+ if (hasCeFlag) {
+ assertWithMessage(errorMsg).that(cePackageDirFile.isDirectory()).isTrue();
+ assertWithMessage(errorMsg).that(
+ cePackageDirFile.list()).asList().containsExactly("one", "two@random");
+ } else {
+ assertWithMessage(errorMsg).that(cePackageDirFile.exists()).isFalse();
+ }
+
+ boolean hasDeFlag = (currentFlag & PackageManagerLocal.FLAG_STORAGE_DE) != 0;
+ if (hasDeFlag) {
+ assertWithMessage(errorMsg).that(dePackageDirFile.isDirectory()).isTrue();
+ assertWithMessage(errorMsg).that(
+ dePackageDirFile.list()).asList().containsExactly("one", "two@random");
+ } else {
+ assertWithMessage(errorMsg).that(dePackageDirFile.exists()).isFalse();
+ }
+ } finally {
+ // Clean up the created directories
+ final List<String> emptyDir = new ArrayList<String>();
+ mPackageManagerLocal.reconcileSdkData(volumeUuid, packageName, emptyDir, userId,
+ appId, previousAppId, seInfo, currentFlag);
+ Files.deleteIfExists(cePackageDirFile.toPath());
+ Files.deleteIfExists(dePackageDirFile.toPath());
+ }
+ }
+ }
+
+ @Test
+ public void testPackageManagerLocal_ReconcileSdkData_Reconcile() throws Exception {
+ final String volumeUuid = null;
+ final String packageName = "android.packagemanagerlocal.test";
+ final List<String> subDirNames = Arrays.asList("one", "two@random");
+ final int userId = 0;
+ final int appId = 10000;
+ final int previousAppId = -1;
+ final String seInfo = "default";
+ final int flag = PackageManagerLocal.FLAG_STORAGE_CE;
+
+ File cePackageDirFile = new File("/data/misc_ce/0/sdksandbox/" + packageName);
+
+ try {
+ mPackageManagerLocal.reconcileSdkData(volumeUuid, packageName, subDirNames, userId,
+ appId, previousAppId, seInfo, flag);
+
+ // Call reconcileSdkData again, with different subDirNames
+ final List<String> differentSubDirNames = Arrays.asList("three");
+ mPackageManagerLocal.reconcileSdkData(volumeUuid, packageName, differentSubDirNames,
+ userId, appId, previousAppId, seInfo, flag);
+
+ // Verify that sdk data directories have been created in the desired location
+ assertThat(cePackageDirFile.isDirectory()).isTrue();
+ assertThat(cePackageDirFile.list()).asList().containsExactly("three");
+ } finally {
+ // Clean up the created directories
+ final List<String> emptyDir = new ArrayList<String>();
+ mPackageManagerLocal.reconcileSdkData(volumeUuid, packageName, emptyDir, userId, appId,
+ previousAppId, seInfo, flag);
+ Files.deleteIfExists(cePackageDirFile.toPath());
+ }
+ }
+}
diff --git a/tests/packagewatchdog/AndroidTest.xml b/tests/packagewatchdog/AndroidTest.xml
index 83b2957..6620098 100644
--- a/tests/packagewatchdog/AndroidTest.xml
+++ b/tests/packagewatchdog/AndroidTest.xml
@@ -18,6 +18,8 @@
<option name="test-suite-tag" value="apct" />
<option name="test-suite-tag" value="apct-instrumentation" />
+ <target_preparer class="com.android.tradefed.targetprep.RootTargetPreparer"/>
+
<target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
<option name="cleanup-apks" value="true"/>
<option name="test-file-name" value="CtsRootPackageWatchdogTestCases.apk"/>
diff --git a/tests/stats/AndroidTest.xml b/tests/stats/AndroidTest.xml
index 55ab762..9eab530 100644
--- a/tests/stats/AndroidTest.xml
+++ b/tests/stats/AndroidTest.xml
@@ -18,6 +18,8 @@
<option name="test-suite-tag" value="apct" />
<option name="test-suite-tag" value="apct-instrumentation" />
+ <target_preparer class="com.android.tradefed.targetprep.RootTargetPreparer"/>
+
<target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
<option name="cleanup-apks" value="true"/>
<option name="test-file-name" value="CtsRootStatsDeviceTestCases.apk"/>
diff --git a/tests/usage/AndroidTest.xml b/tests/usage/AndroidTest.xml
index ef4c8ad..6ea4a99 100644
--- a/tests/usage/AndroidTest.xml
+++ b/tests/usage/AndroidTest.xml
@@ -18,6 +18,8 @@
<option name="test-suite-tag" value="apct" />
<option name="test-suite-tag" value="apct-instrumentation" />
+ <target_preparer class="com.android.tradefed.targetprep.RootTargetPreparer"/>
+
<target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
<option name="cleanup-apks" value="true"/>
<option name="test-file-name" value="CtsRootUsageDeviceTestCases.apk"/>