Add WorkProfileAndroidTest.xml
Test: atest CrossProfileAppsTest
Bug: 167945074
Change-Id: I7fbca98e37125b3a07380a12572d7194224d92c9
diff --git a/tests/devicepolicy/Android.bp b/tests/devicepolicy/Android.bp
index de0c439..049779e 100644
--- a/tests/devicepolicy/Android.bp
+++ b/tests/devicepolicy/Android.bp
@@ -28,5 +28,8 @@
"vts10",
"general-tests",
],
+ test_options: {
+ extra_test_configs: ["WorkProfileAndroidTest.xml"]
+ },
sdk_version: "test_current",
}
diff --git a/tests/devicepolicy/AndroidManifest.xml b/tests/devicepolicy/AndroidManifest.xml
index c8df754..a809d68 100644
--- a/tests/devicepolicy/AndroidManifest.xml
+++ b/tests/devicepolicy/AndroidManifest.xml
@@ -21,6 +21,31 @@
<application>
<uses-library android:name="android.test.runner" />
+
+ <activity android:name=".MainActivity"
+ android:exported="true">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN"/>
+ <category android:name="android.intent.category.LAUNCHER"/>
+ <category android:name="android.intent.category.DEFAULT"/>
+ </intent-filter>
+ </activity>
+
+ <activity android:name=".NonMainActivity"
+ android:exported="true">
+ <intent-filter>
+ <action android:name="nonMainActivity"/>
+ </intent-filter>
+ </activity>
+
+ <activity android:name=".NonExportedActivity"
+ android:exported="false">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN"/>
+ <category android:name="android.intent.category.LAUNCHER"/>
+ <category android:name="android.intent.category.DEFAULT"/>
+ </intent-filter>
+ </activity>
</application>
<instrumentation android:name="androidx.test.runner.AndroidJUnitRunner"
android:targetPackage="android.devicepolicy.cts"
diff --git a/tests/devicepolicy/AndroidTest.xml b/tests/devicepolicy/AndroidTest.xml
index 594ff57..14ef3f5 100644
--- a/tests/devicepolicy/AndroidTest.xml
+++ b/tests/devicepolicy/AndroidTest.xml
@@ -1,30 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
-<!--
- ~ Copyright (C) 2020 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 CTS File System test cases">
- <option name="test-suite-tag" value="cts" />
- <option name="config-descriptor:metadata" key="component" value="framework" />
- <option name="config-descriptor:metadata" key="parameter" value="instant_app" />
- <option name="config-descriptor:metadata" key="parameter" value="multi_abi" />
- <option name="config-descriptor:metadata" key="parameter" value="secondary_user" />
- <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
- <option name="cleanup-apks" value="true" />
- <option name="test-file-name" value="CtsDevicePolicyTestCases.apk" />
- </target_preparer>
- <test class="com.android.tradefed.testtype.AndroidJUnitTest" >
- <option name="package" value="android.devicepolicy.cts" />
- </test>
-</configuration>
+<!-- Copyright (C) 2020 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 CTS Device Policy test cases">
+<option name="test-suite-tag" value="cts" />
+<option name="config-descriptor:metadata" key="component" value="framework" />
+<option name="config-descriptor:metadata" key="parameter" value="instant_app" />
+<option name="config-descriptor:metadata" key="parameter" value="multi_abi" />
+<option name="config-descriptor:metadata" key="parameter" value="secondary_user" />
+<target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
+ <option name="cleanup-apks" value="true" />
+ <option name="test-file-name" value="CtsDevicePolicyTestCases.apk" />
+</target_preparer>
+<test class="com.android.tradefed.testtype.AndroidJUnitTest" >
+ <option name="package" value="android.devicepolicy.cts" />
+ <option name="exclude-annotation" value="com.android.compatibility.common.util.enterprise.annotations.RequireRunOnWorkProfile" />
+</test>
+</configuration>
\ No newline at end of file
diff --git a/tests/devicepolicy/WorkProfileAndroidTest.xml b/tests/devicepolicy/WorkProfileAndroidTest.xml
new file mode 100644
index 0000000..8b408af
--- /dev/null
+++ b/tests/devicepolicy/WorkProfileAndroidTest.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2020 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 CTS Device Policy test cases on a work profile">
+ <option name="test-suite-tag" value="cts" />
+ <option name="config-descriptor:metadata" key="component" value="framework" />
+ <option name="config-descriptor:metadata" key="parameter" value="instant_app" />
+ <option name="config-descriptor:metadata" key="parameter" value="multi_abi" />
+ <option name="config-descriptor:metadata" key="parameter" value="secondary_user" />
+ <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
+ <option name="cleanup-apks" value="true" />
+ <option name="test-file-name" value="CtsDevicePolicyTestCases.apk" />
+ </target_preparer>
+ <target_preparer class="com.android.tradefed.targetprep.RunOnWorkProfileTargetPreparer">
+ <option name="test-package-name" value="android.devicepolicy.cts" />
+ </target_preparer>
+ <test class="com.android.tradefed.testtype.AndroidJUnitTest" >
+ <option name="package" value="android.devicepolicy.cts" />
+ <option name="include-annotation" value="com.android.compatibility.common.util.enterprise.annotations.RequireRunOnWorkProfile" />
+ </test>
+</configuration>
\ No newline at end of file
diff --git a/tests/devicepolicy/src/android/devicepolicy/cts/CrossProfileAppsTest.java b/tests/devicepolicy/src/android/devicepolicy/cts/CrossProfileAppsTest.java
index d52d116..6009351 100644
--- a/tests/devicepolicy/src/android/devicepolicy/cts/CrossProfileAppsTest.java
+++ b/tests/devicepolicy/src/android/devicepolicy/cts/CrossProfileAppsTest.java
@@ -31,8 +31,10 @@
import com.android.compatibility.common.util.enterprise.DeviceState;
import com.android.compatibility.common.util.enterprise.Preconditions;
import com.android.compatibility.common.util.enterprise.annotations.RequireRunOnPrimaryUser;
+import com.android.compatibility.common.util.enterprise.annotations.RequireRunOnWorkProfile;
import org.junit.ClassRule;
+import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -61,6 +63,46 @@
}
@Test
+ @RequireRunOnWorkProfile
+ public void getTargetUserProfiles_callingFromWorkProfile_containsPrimaryUser() {
+ List<UserHandle> targetProfiles = sCrossProfileApps.getTargetUserProfiles();
+
+ assertThat(targetProfiles).contains(sDeviceState.getPrimaryUser());
+ }
+
+ // TODO(scottjonathan): Add
+ // startMainActivity_callingFromWorkProfile_targetIsPrimaryUser_launches
+
+ @Test
+ @RequireRunOnWorkProfile
+ public void startMainActivity_activityNotExported_throwsSecurityException() {
+ assertThrows(SecurityException.class, () -> {
+ sCrossProfileApps.startMainActivity(
+ new ComponentName(
+ sContext, NonExportedActivity.class), sDeviceState.getPrimaryUser());
+ });
+ }
+
+ @Test
+ @RequireRunOnWorkProfile
+ public void startMainActivity_activityNotMain_throwsSecurityException() {
+ assertThrows(SecurityException.class, () -> {
+ sCrossProfileApps.startMainActivity(
+ new ComponentName(
+ sContext, NonMainActivity.class), sDeviceState.getPrimaryUser());
+ });
+ }
+
+ @Test
+ @RequireRunOnWorkProfile
+ @Ignore // TODO(scottjonathan): This requires another app to be installed which can be launched
+ public void startMainActivity_activityIncorrectPackage_throwsSecurityException() {
+ assertThrows(SecurityException.class, () -> {
+
+ });
+ }
+
+ @Test
@RequireRunOnPrimaryUser
public void
startMainActivity_callingFromPrimaryUser_targetIsPrimaryUser_throwsSecurityException() {
@@ -79,6 +121,14 @@
}
@Test
+ @RequireRunOnWorkProfile
+ public void getProfileSwitchingLabel_callingFromWorkUser_targetIsPrimaryUser_notNull() {
+ assertThat(
+ sCrossProfileApps.getProfileSwitchingLabel(
+ sDeviceState.getPrimaryUser())).isNotNull();
+ }
+
+ @Test
@RequireRunOnPrimaryUser
public void getProfileSwitchingLabelIconDrawable_callingFromPrimaryUser_targetIsPrimaryUser_throwsSecurityException() {
assertThrows(SecurityException.class, () -> {
@@ -86,4 +136,12 @@
});
}
+ @Test
+ @RequireRunOnWorkProfile
+ public void getProfileSwitchingIconDrawable_callingFromWorkUser_targetIsPrimaryUser_notNull() {
+ assertThat(
+ sCrossProfileApps.getProfileSwitchingIconDrawable(
+ sDeviceState.getPrimaryUser())).isNotNull();
+ }
+
}
diff --git a/tests/devicepolicy/src/android/devicepolicy/cts/MainActivity.java b/tests/devicepolicy/src/android/devicepolicy/cts/MainActivity.java
index ce30e61..fbad8ae 100644
--- a/tests/devicepolicy/src/android/devicepolicy/cts/MainActivity.java
+++ b/tests/devicepolicy/src/android/devicepolicy/cts/MainActivity.java
@@ -18,5 +18,6 @@
import android.app.Activity;
+/** Activity used for Cross Profile Apps Tests */
public class MainActivity extends Activity {
}
diff --git a/tests/devicepolicy/src/android/devicepolicy/cts/NonExportedActivity.java b/tests/devicepolicy/src/android/devicepolicy/cts/NonExportedActivity.java
new file mode 100644
index 0000000..a76f4ee
--- /dev/null
+++ b/tests/devicepolicy/src/android/devicepolicy/cts/NonExportedActivity.java
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2020 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.devicepolicy.cts;
+
+import android.app.Activity;
+
+/** Activity used for Cross Profile Apps Tests */
+public class NonExportedActivity extends Activity {
+}
diff --git a/tests/devicepolicy/src/android/devicepolicy/cts/NonMainActivity.java b/tests/devicepolicy/src/android/devicepolicy/cts/NonMainActivity.java
new file mode 100644
index 0000000..7ef5f8a
--- /dev/null
+++ b/tests/devicepolicy/src/android/devicepolicy/cts/NonMainActivity.java
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2020 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.devicepolicy.cts;
+
+import android.app.Activity;
+
+/** Activity used for Cross Profile Apps Tests */
+public class NonMainActivity extends Activity {
+}