Merge "Created CTS tests to verify property access with no property permissions and with just permission CAR_INFO granted." into stage-aosp-sc-ts-dev
diff --git a/tests/tests/car/AndroidTest.xml b/tests/tests/car/AndroidTest.xml
index e9a83e8..ddbc16a 100644
--- a/tests/tests/car/AndroidTest.xml
+++ b/tests/tests/car/AndroidTest.xml
@@ -14,18 +14,33 @@
limitations under the License.
-->
<configuration description="Config for CTS Automotive test cases">
- <option name="test-suite-tag" value="cts" />
- <option name="config-descriptor:metadata" key="component" value="auto" />
- <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" />
+ <object class="com.android.tradefed.testtype.suite.module.CarModuleController"
+ type="module_controller"/>
+ <option name="test-suite-tag" value="cts"/>
+ <option name="config-descriptor:metadata" key="component" value="auto"/>
+ <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="CtsCarTestCases.apk" />
+ <option name="cleanup-apks" value="true"/>
+ <option name="test-file-name" value="CtsCarTestCases.apk"/>
+ <option name="test-file-name" value="CtsCarPermissionCarInfoTest.apk"/>
+ <option name="test-file-name" value="CtsCarNoPropertyPermissionsTest.apk"/>
</target_preparer>
- <test class="com.android.tradefed.testtype.AndroidJUnitTest" >
- <option name="package" value="android.car.cts" />
+
+ <test class="com.android.tradefed.testtype.AndroidJUnitTest">
+ <option name="package" value="android.car.cts"/>
</test>
- <object type="module_controller" class="com.android.tradefed.testtype.suite.module.CarModuleController"/>
+ <test class="com.android.tradefed.testtype.AndroidJUnitTest">
+ <option name="package" value="android.car.cts.nopropertypermissions"/>
+ <option name="class"
+ value="android.car.cts.nopropertypermissions.NoPropertyPermissionsTest"/>
+ </test>
+ <test class="com.android.tradefed.testtype.AndroidJUnitTest">
+ <option name="package" value="android.car.cts.permissioncarinfo"/>
+ <option name="class"
+ value="android.car.cts.permissioncarinfo.PermissionCarInfoTest"/>
+ </test>
</configuration>
diff --git a/tests/tests/car/NoPropertyPermissions/Android.bp b/tests/tests/car/NoPropertyPermissions/Android.bp
new file mode 100644
index 0000000..dd03938
--- /dev/null
+++ b/tests/tests/car/NoPropertyPermissions/Android.bp
@@ -0,0 +1,40 @@
+// 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 {
+ default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+android_test_helper_app {
+ name: "CtsCarNoPropertyPermissionsTest",
+ defaults: ["cts_defaults"],
+ sdk_version: "current",
+ srcs: [
+ "src/**/*.java",
+ ],
+ // Tag this module as a cts test artifact
+ test_suites: [
+ "cts",
+ "general-tests",
+ ],
+ static_libs: [
+ "compatibility-device-util-axt",
+ "truth-prebuilt",
+ "ctstestrunner-axt",
+ ],
+ libs: [
+ "android.test.base",
+ "android.car-test-stubs",
+ ],
+}
\ No newline at end of file
diff --git a/tests/tests/car/NoPropertyPermissions/AndroidManifest.xml b/tests/tests/car/NoPropertyPermissions/AndroidManifest.xml
new file mode 100644
index 0000000..25178f9
--- /dev/null
+++ b/tests/tests/car/NoPropertyPermissions/AndroidManifest.xml
@@ -0,0 +1,30 @@
+<?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.
+ -->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="android.car.cts.nopropertypermissions">
+ <application android:label="NoPropertyPermissions">
+ <uses-library android:name="android.test.runner"/>
+ </application>
+
+ <instrumentation android:name="androidx.test.runner.AndroidJUnitRunner"
+ android:functionalTest="true"
+ android:label="No Property Permissions Test"
+ android:targetPackage="android.car.cts.nopropertypermissions">
+ </instrumentation>
+
+ <uses-feature android:name="android.hardware.type.automotive"/>
+</manifest>
\ No newline at end of file
diff --git a/tests/tests/car/NoPropertyPermissions/src/android/car/cts/nopropertypermissions/NoPropertyPermissionsTest.java b/tests/tests/car/NoPropertyPermissions/src/android/car/cts/nopropertypermissions/NoPropertyPermissionsTest.java
new file mode 100644
index 0000000..d59c7a3
--- /dev/null
+++ b/tests/tests/car/NoPropertyPermissions/src/android/car/cts/nopropertypermissions/NoPropertyPermissionsTest.java
@@ -0,0 +1,54 @@
+/*
+ * 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 android.car.cts.nopropertypermissions;
+
+import static com.google.common.truth.Truth.assertWithMessage;
+import static com.google.common.truth.Truth.assertThat;
+
+import android.car.Car;
+import android.car.hardware.property.CarPropertyManager;
+import android.platform.test.annotations.AppModeFull;
+import android.platform.test.annotations.RequiresDevice;
+
+import androidx.test.platform.app.InstrumentationRegistry;
+import androidx.test.runner.AndroidJUnit4;
+
+import org.junit.Test;
+import org.junit.Before;
+import org.junit.runner.RunWith;
+
+@RequiresDevice
+@RunWith(AndroidJUnit4.class)
+@AppModeFull(reason = "Instant apps cannot get car related permissions.")
+public final class NoPropertyPermissionsTest {
+ private CarPropertyManager mCarPropertyManager;
+
+ @Before
+ public void setUp() {
+ mCarPropertyManager =
+ (CarPropertyManager) Car.createCar(
+ InstrumentationRegistry.getInstrumentation().getContext()).getCarManager(
+ Car.PROPERTY_SERVICE);
+ assertThat(mCarPropertyManager).isNotNull();
+ }
+
+ @Test
+ public void testNoPropertyPermissionsGranted() {
+ assertWithMessage("CarPropertyManager.getPropertyList()").that(
+ mCarPropertyManager.getPropertyList()).isEmpty();
+ }
+}
\ No newline at end of file
diff --git a/tests/tests/car/PermissionCarInfo/Android.bp b/tests/tests/car/PermissionCarInfo/Android.bp
new file mode 100644
index 0000000..ca32621
--- /dev/null
+++ b/tests/tests/car/PermissionCarInfo/Android.bp
@@ -0,0 +1,40 @@
+// 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 {
+ default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+android_test_helper_app {
+ name: "CtsCarPermissionCarInfoTest",
+ defaults: ["cts_defaults"],
+ sdk_version: "current",
+ srcs: [
+ "src/**/*.java",
+ ],
+ // Tag this module as a cts test artifact
+ test_suites: [
+ "cts",
+ "general-tests",
+ ],
+ static_libs: [
+ "compatibility-device-util-axt",
+ "truth-prebuilt",
+ "ctstestrunner-axt",
+ ],
+ libs: [
+ "android.test.base",
+ "android.car-test-stubs",
+ ],
+}
\ No newline at end of file
diff --git a/tests/tests/car/PermissionCarInfo/AndroidManifest.xml b/tests/tests/car/PermissionCarInfo/AndroidManifest.xml
new file mode 100644
index 0000000..4e6f827
--- /dev/null
+++ b/tests/tests/car/PermissionCarInfo/AndroidManifest.xml
@@ -0,0 +1,33 @@
+<?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.
+ -->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="android.car.cts.permissioncarinfo">
+ <application android:label="PermissionCarInfo">
+ <uses-library android:name="android.test.runner"/>
+ </application>
+
+ <instrumentation android:name="androidx.test.runner.AndroidJUnitRunner"
+ android:functionalTest="true"
+ android:label="Permission CAR_INFO Test"
+ android:targetPackage="android.car.cts.permissioncarinfo">
+ </instrumentation>
+
+ <uses-feature android:name="android.hardware.type.automotive"/>
+
+ <uses-permission android:name="android.car.permission.CAR_INFO"/>
+</manifest>
+
diff --git a/tests/tests/car/PermissionCarInfo/src/android/car/cts/permissioncarinfo/PermissionCarInfoTest.java b/tests/tests/car/PermissionCarInfo/src/android/car/cts/permissioncarinfo/PermissionCarInfoTest.java
new file mode 100644
index 0000000..5757d6c
--- /dev/null
+++ b/tests/tests/car/PermissionCarInfo/src/android/car/cts/permissioncarinfo/PermissionCarInfoTest.java
@@ -0,0 +1,75 @@
+/*
+ * 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 android.car.cts.permissioncarinfo;
+
+import static com.google.common.truth.Truth.assertThat;
+import static com.google.common.truth.Truth.assertWithMessage;
+
+import android.car.Car;
+import android.car.VehiclePropertyIds;
+import android.car.hardware.CarPropertyConfig;
+import android.car.hardware.property.CarPropertyManager;
+import android.platform.test.annotations.AppModeFull;
+import android.platform.test.annotations.RequiresDevice;
+
+import androidx.test.platform.app.InstrumentationRegistry;
+import androidx.test.runner.AndroidJUnit4;
+
+import com.google.common.collect.ImmutableList;
+
+import org.junit.Test;
+import org.junit.Before;
+import org.junit.runner.RunWith;
+
+@RequiresDevice
+@RunWith(AndroidJUnit4.class)
+@AppModeFull(reason = "Instant apps cannot get car related permissions.")
+public final class PermissionCarInfoTest {
+ private static final ImmutableList<Integer> PERMISSION_CAR_INFO_PROPERTIES =
+ ImmutableList.<Integer>builder().add(
+ VehiclePropertyIds.INFO_MAKE, VehiclePropertyIds.INFO_MODEL,
+ VehiclePropertyIds.INFO_MODEL_YEAR, VehiclePropertyIds.INFO_FUEL_CAPACITY,
+ VehiclePropertyIds.INFO_FUEL_TYPE, VehiclePropertyIds.INFO_EV_BATTERY_CAPACITY,
+ VehiclePropertyIds.INFO_EV_CONNECTOR_TYPE,
+ VehiclePropertyIds.INFO_FUEL_DOOR_LOCATION,
+ VehiclePropertyIds.INFO_MULTI_EV_PORT_LOCATIONS,
+ VehiclePropertyIds.INFO_EV_PORT_LOCATION, VehiclePropertyIds.INFO_DRIVER_SEAT,
+ VehiclePropertyIds.INFO_EXTERIOR_DIMENSIONS,
+ VehiclePropertyIds.ELECTRONIC_TOLL_COLLECTION_CARD_TYPE,
+ VehiclePropertyIds.ELECTRONIC_TOLL_COLLECTION_CARD_STATUS)
+ .build();
+
+ private CarPropertyManager mCarPropertyManager;
+
+ @Before
+ public void setUp() {
+ mCarPropertyManager =
+ (CarPropertyManager) Car.createCar(
+ InstrumentationRegistry.getInstrumentation().getContext()).getCarManager(
+ Car.PROPERTY_SERVICE);
+ assertThat(mCarPropertyManager).isNotNull();
+ }
+
+ @Test
+ public void testPermissionCarInfoGranted() {
+ for (CarPropertyConfig<?> carPropertyConfig : mCarPropertyManager.getPropertyList()) {
+ assertWithMessage("%s",
+ VehiclePropertyIds.toString(carPropertyConfig.getPropertyId())).that(
+ carPropertyConfig.getPropertyId()).isIn(PERMISSION_CAR_INFO_PROPERTIES);
+ }
+ }
+}