diff options
93 files changed, 804 insertions, 496 deletions
diff --git a/SafetyCenter/Config/Android.bp b/SafetyCenter/Config/Android.bp new file mode 100644 index 000000000..afe7c380a --- /dev/null +++ b/SafetyCenter/Config/Android.bp @@ -0,0 +1,38 @@ +// +// 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"], +} + +java_library { + name: "safety-center-config", + sdk_version: "module_current", + min_sdk_version: "30", + target_sdk_version: "32", + srcs: [ + "java/**/*.java", + ], + libs: [ + "androidx.annotation_annotation", + "framework-annotations-lib", + "framework-permission-s", + ], + apex_available: [ + "com.android.permission", + "test_com.android.permission", + ], + installable: false, +} diff --git a/framework-s/java/android/safetycenter/config/ParseException.java b/SafetyCenter/Config/java/com/android/safetycenter/config/ParseException.java index 76ba94245..e73f98484 100644 --- a/framework-s/java/android/safetycenter/config/ParseException.java +++ b/SafetyCenter/Config/java/com/android/safetycenter/config/ParseException.java @@ -14,21 +14,15 @@ * limitations under the License. */ -package android.safetycenter.config; +package com.android.safetycenter.config; import static android.os.Build.VERSION_CODES.TIRAMISU; import android.annotation.NonNull; -import android.annotation.SystemApi; import androidx.annotation.RequiresApi; -/** - * Exception thrown when there is an error parsing the Safety Center configuration. - * - * @hide - */ -@SystemApi +/** Exception thrown when there is an error parsing the Safety Center configuration. */ @RequiresApi(TIRAMISU) public final class ParseException extends Exception { diff --git a/framework-s/java/android/safetycenter/config/SafetyCenterConfigParser.java b/SafetyCenter/Config/java/com/android/safetycenter/config/SafetyCenterConfigParser.java index 45d5c9f2f..fc933bdcd 100644 --- a/framework-s/java/android/safetycenter/config/SafetyCenterConfigParser.java +++ b/SafetyCenter/Config/java/com/android/safetycenter/config/SafetyCenterConfigParser.java @@ -14,12 +14,13 @@ * limitations under the License. */ -package android.safetycenter.config; +package com.android.safetycenter.config; import static android.os.Build.VERSION_CODES.TIRAMISU; import static org.xmlpull.v1.XmlPullParser.END_DOCUMENT; import static org.xmlpull.v1.XmlPullParser.END_TAG; +import static org.xmlpull.v1.XmlPullParser.FEATURE_PROCESS_NAMESPACES; import static org.xmlpull.v1.XmlPullParser.START_DOCUMENT; import static org.xmlpull.v1.XmlPullParser.START_TAG; import static org.xmlpull.v1.XmlPullParser.TEXT; @@ -30,20 +31,22 @@ import static java.util.Objects.requireNonNull; import android.annotation.NonNull; import android.annotation.StringRes; import android.content.res.Resources; -import android.content.res.XmlResourceParser; -import android.safetycenter.config.SafetySource.InitialDisplayState; -import android.safetycenter.config.SafetySource.Profile; -import android.safetycenter.config.SafetySource.SafetySourceType; -import android.safetycenter.config.SafetySourcesGroup.StatelessIconType; +import android.safetycenter.config.SafetyCenterConfig; +import android.safetycenter.config.SafetySource; +import android.safetycenter.config.SafetySourcesGroup; import androidx.annotation.RequiresApi; +import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; +import org.xmlpull.v1.XmlPullParserFactory; import java.io.IOException; +import java.io.InputStream; +/** Parser and validator for {@link SafetyCenterConfig} objects. */ @RequiresApi(TIRAMISU) -final class SafetyCenterConfigParser { +public final class SafetyCenterConfigParser { private static final String TAG_SAFETY_CENTER_CONFIG = "safety-center-config"; private static final String TAG_SAFETY_SOURCES_CONFIG = "safety-sources-config"; @@ -79,18 +82,32 @@ final class SafetyCenterConfigParser { private SafetyCenterConfigParser() { } + /** + * Parses and validates the given XML resource into a {@link SafetyCenterConfig} object. + * + * <p>It throws a {@link ParseException} if the given XML resource does not comply with the + * safety_center_config.xsd schema. + * + * @param in the raw XML resource representing the Safety Center configuration + * @param resources the {@link Resources} retrieved from the package that contains the Safety + * Center configuration + */ @NonNull - static SafetyCenterConfig parseXmlResource(@NonNull XmlResourceParser parser) - throws ParseException { - requireNonNull(parser); + public static SafetyCenterConfig parseXmlResource( + @NonNull InputStream in, @NonNull Resources resources) throws ParseException { + requireNonNull(in); + requireNonNull(resources); try { - parser.next(); + XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser(); + parser.setFeature(FEATURE_PROCESS_NAMESPACES, true); + parser.setInput(in, null); if (parser.getEventType() != START_DOCUMENT) { throw new ParseException("Unexpected parser state"); } parser.nextTag(); validateElementStart(parser, TAG_SAFETY_CENTER_CONFIG); - SafetyCenterConfig safetyCenterConfig = parseSafetyCenterConfig(parser); + SafetyCenterConfig safetyCenterConfig = + parseSafetyCenterConfig(parser, resources); if (parser.getEventType() == TEXT && parser.isWhitespace()) { parser.next(); } @@ -104,7 +121,8 @@ final class SafetyCenterConfigParser { } @NonNull - private static SafetyCenterConfig parseSafetyCenterConfig(@NonNull XmlResourceParser parser) + private static SafetyCenterConfig parseSafetyCenterConfig( + @NonNull XmlPullParser parser, @NonNull Resources resources) throws XmlPullParserException, IOException, ParseException { validateElementHasNoAttribute(parser, TAG_SAFETY_CENTER_CONFIG); parser.nextTag(); @@ -114,7 +132,8 @@ final class SafetyCenterConfigParser { parser.nextTag(); while (parser.getEventType() == START_TAG && parser.getName().equals(TAG_SAFETY_SOURCES_GROUP)) { - builder.addSafetySourcesGroup(parseSafetySourcesGroup(parser)); + builder.addSafetySourcesGroup( + parseSafetySourcesGroup(parser, resources)); } validateElementEnd(parser, TAG_SAFETY_SOURCES_CONFIG); parser.nextTag(); @@ -128,7 +147,8 @@ final class SafetyCenterConfigParser { } @NonNull - private static SafetySourcesGroup parseSafetySourcesGroup(@NonNull XmlResourceParser parser) + private static SafetySourcesGroup parseSafetySourcesGroup( + @NonNull XmlPullParser parser, @NonNull Resources resources) throws XmlPullParserException, IOException, ParseException { String name = TAG_SAFETY_SOURCES_GROUP; SafetySourcesGroup.Builder builder = new SafetySourcesGroup.Builder(); @@ -138,10 +158,14 @@ final class SafetyCenterConfigParser { builder.setId(parser.getAttributeValue(i)); break; case ATTR_SAFETY_SOURCES_GROUP_TITLE: - builder.setTitleResId(parseStringReference(parser, i, name)); + builder.setTitleResId( + parseStringResourceName(parser.getAttributeValue(i), name, + parser.getAttributeName(i), resources)); break; case ATTR_SAFETY_SOURCES_GROUP_SUMMARY: - builder.setSummaryResId(parseStringReference(parser, i, name)); + builder.setSummaryResId( + parseStringResourceName(parser.getAttributeValue(i), name, + parser.getAttributeName(i), resources)); break; case ATTR_SAFETY_SOURCES_GROUP_STATELESS_ICON_TYPE: builder.setStatelessIconType( @@ -169,7 +193,8 @@ final class SafetyCenterConfigParser { default: break loop; } - builder.addSafetySource(parseSafetySource(parser, type, parser.getName())); + builder.addSafetySource( + parseSafetySource(parser, resources, type, parser.getName())); } validateElementEnd(parser, name); parser.nextTag(); @@ -182,9 +207,12 @@ final class SafetyCenterConfigParser { @NonNull private static SafetySource parseSafetySource( - @NonNull XmlResourceParser parser, @SafetySourceType int type, @NonNull String name) - throws XmlPullParserException, IOException, ParseException { - SafetySource.Builder builder = new SafetySource.Builder(type); + @NonNull XmlPullParser parser, + @NonNull Resources resources, + int safetySourceType, + @NonNull String name + ) throws XmlPullParserException, IOException, ParseException { + SafetySource.Builder builder = new SafetySource.Builder(safetySourceType); for (int i = 0; i < parser.getAttributeCount(); i++) { switch (parser.getAttributeName(i)) { case ATTR_SAFETY_SOURCE_ID: @@ -194,13 +222,19 @@ final class SafetyCenterConfigParser { builder.setPackageName(parser.getAttributeValue(i)); break; case ATTR_SAFETY_SOURCE_TITLE: - builder.setTitleResId(parseStringReference(parser, i, name)); + builder.setTitleResId( + parseStringResourceName(parser.getAttributeValue(i), name, + parser.getAttributeName(i), resources)); break; case ATTR_SAFETY_SOURCE_TITLE_FOR_WORK: - builder.setTitleForWorkResId(parseStringReference(parser, i, name)); + builder.setTitleForWorkResId( + parseStringResourceName(parser.getAttributeValue(i), name, + parser.getAttributeName(i), resources)); break; case ATTR_SAFETY_SOURCE_SUMMARY: - builder.setSummaryResId(parseStringReference(parser, i, name)); + builder.setSummaryResId( + parseStringResourceName(parser.getAttributeValue(i), name, + parser.getAttributeName(i), resources)); break; case ATTR_SAFETY_SOURCE_INTENT_ACTION: builder.setIntentAction(parser.getAttributeValue(i)); @@ -221,7 +255,9 @@ final class SafetyCenterConfigParser { parser.getAttributeName(i))); break; case ATTR_SAFETY_SOURCE_SEARCH_TERMS: - builder.setSearchTermsResId(parseStringReference(parser, i, name)); + builder.setSearchTermsResId( + parseStringResourceName(parser.getAttributeValue(i), name, + parser.getAttributeName(i), resources)); break; case ATTR_SAFETY_SOURCE_LOGGING_ALLOWED: builder.setLoggingAllowed( @@ -247,15 +283,14 @@ final class SafetyCenterConfigParser { } } - private static void validateElementStart(@NonNull XmlResourceParser parser, - @NonNull String name) + private static void validateElementStart(@NonNull XmlPullParser parser, @NonNull String name) throws XmlPullParserException, ParseException { if (parser.getEventType() != START_TAG || !parser.getName().equals(name)) { throw elementMissing(name); } } - private static void validateElementEnd(@NonNull XmlResourceParser parser, @NonNull String name) + private static void validateElementEnd(@NonNull XmlPullParser parser, @NonNull String name) throws XmlPullParserException, ParseException { if (parser.getEventType() != END_TAG || !parser.getName().equals(name)) { throw elementNotClosed(name); @@ -263,7 +298,7 @@ final class SafetyCenterConfigParser { } private static void validateElementHasNoAttribute( - @NonNull XmlResourceParser parser, @NonNull String name) throws ParseException { + @NonNull XmlPullParser parser, @NonNull String name) throws ParseException { if (parser.getAttributeCount() != 0) { throw elementInvalid(name); } @@ -317,21 +352,47 @@ final class SafetyCenterConfigParser { } @StringRes - private static int parseStringReference( - @NonNull XmlResourceParser parser, int index, @NonNull String parent) - throws ParseException { - int id = parser.getAttributeResourceValue(index, Resources.ID_NULL); + private static int parseStringResourceName( + @NonNull String valueString, @NonNull String parent, @NonNull String name, + @NonNull Resources resources) throws ParseException { + if (valueString.isEmpty()) { + throw new ParseException( + String.format("Resource name in %s.%s cannot be empty", parent, name)); + } + if (valueString.charAt(0) != '@') { + throw new ParseException( + String.format("Resource name %s in %s.%s does not start with @", valueString, + parent, name)); + } + String[] colonSplit = valueString.substring(1).split(":", 2); + if (colonSplit.length != 2 || colonSplit[0].isEmpty()) { + throw new ParseException( + String.format("Resource name %s in %s.%s does not specify a package", + valueString, parent, name)); + } + String packageName = colonSplit[0]; + String[] slashSplit = colonSplit[1].split("/", 2); + if (slashSplit.length != 2 || slashSplit[0].isEmpty()) { + throw new ParseException( + String.format("Resource name %s in %s.%s does not specify a type", + valueString, parent, name)); + } + String type = slashSplit[0]; + if (!type.equals("string")) { + throw new ParseException( + String.format("Resource name %s in %s.%s is not a string", valueString, parent, + name)); + } + String entry = slashSplit[1]; + int id = resources.getIdentifier(entry, type, packageName); if (id == Resources.ID_NULL) { throw new ParseException( - String.format( - "Reference %s in %s.%s missing or invalid", - parser.getAttributeValue(index), parent, - parser.getAttributeName(index))); + String.format("Resource name %s in %s.%s missing or invalid", valueString, + parent, name)); } return id; } - @StatelessIconType private static int parseStatelessIconType( @NonNull String valueString, @NonNull String parent, @NonNull String name) throws ParseException { @@ -345,7 +406,6 @@ final class SafetyCenterConfigParser { } } - @Profile private static int parseProfile( @NonNull String valueString, @NonNull String parent, @NonNull String name) throws ParseException { @@ -359,7 +419,6 @@ final class SafetyCenterConfigParser { } } - @InitialDisplayState private static int parseInitialDisplayState( @NonNull String valueString, @NonNull String parent, @NonNull String name) throws ParseException { diff --git a/SafetyCenter/Config/safety_center_config.xsd b/SafetyCenter/Config/safety_center_config.xsd index 400380d24..5a3576dd5 100644 --- a/SafetyCenter/Config/safety_center_config.xsd +++ b/SafetyCenter/Config/safety_center_config.xsd @@ -43,8 +43,8 @@ <!-- id must be unique among safety sources groups --> <xsd:attribute name="id" type="xsd:string" use="required"/> <!-- title is required unless the group contains issue only and/or internal sources --> - <xsd:attribute name="title" type="reference"/> - <xsd:attribute name="summary" type="reference"/> + <xsd:attribute name="title" type="stringResourceName"/> + <xsd:attribute name="summary" type="stringResourceName"/> <xsd:attribute name="statelessIconType" type="statelessIconType" default="none"/> </xsd:complexType> @@ -118,10 +118,11 @@ </xsd:restriction> </xsd:simpleType> - <!-- NOTE: string references will be ignored for any attribute not explicitly marked as reference in this schema --> - <xsd:simpleType name="reference"> + <!-- NOTE: stringResourceNames will be ignored for any attribute not explicitly marked as stringResourceName in this schema. --> + <!-- A stringResourceNames is a fully qualified resource name of the form "@package:string/entry". Package is required. --> + <xsd:simpleType name="stringResourceName"> <xsd:restriction base="xsd:string"> - <xsd:pattern value="@string/.+"/> + <xsd:pattern value="@([a-z]+\.)*[a-z]+:string/.+"/> </xsd:restriction> </xsd:simpleType> diff --git a/SafetyCenter/Config/tests/Android.bp b/SafetyCenter/Config/tests/Android.bp new file mode 100644 index 000000000..57e6f6b3f --- /dev/null +++ b/SafetyCenter/Config/tests/Android.bp @@ -0,0 +1,36 @@ +// 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: "SafetyCenterConfigTests", + defaults: ["mts-target-sdk-version-current"], + sdk_version: "test_current", + min_sdk_version: "30", + target_sdk_version: "32", + srcs: [ + "java/**/*.kt", + ], + static_libs: [ + "safety-center-config", + "compatibility-device-util-axt", + ], + test_suites: [ + "general-tests", + "mts-permission", + ], +} diff --git a/SafetyCenter/Config/tests/AndroidManifest.xml b/SafetyCenter/Config/tests/AndroidManifest.xml new file mode 100644 index 000000000..2c32464f0 --- /dev/null +++ b/SafetyCenter/Config/tests/AndroidManifest.xml @@ -0,0 +1,30 @@ +<?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. + --> + +<manifest + xmlns:android="http://schemas.android.com/apk/res/android" + package="com.android.safetycenter.config.tests"> + + <application android:label="Safety Center Config Tests"> + <uses-library android:name="android.test.runner" /> + </application> + + <instrumentation android:name="androidx.test.runner.AndroidJUnitRunner" + android:targetPackage="com.android.safetycenter.config.tests" + android:label="Tests for the Safety Center Config library" /> +</manifest> diff --git a/SafetyCenter/Config/tests/AndroidTest.xml b/SafetyCenter/Config/tests/AndroidTest.xml new file mode 100644 index 000000000..1874ce0c3 --- /dev/null +++ b/SafetyCenter/Config/tests/AndroidTest.xml @@ -0,0 +1,35 @@ +<?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 unit tests for the Safety Center Config library."> + <option name="test-suite-tag" value="apct" /> + <option name="test-suite-tag" value="apct-instrumentation" /> + <option name="test-tag" value="SafetyCenterConfigTests" /> + <object type="module_controller" class="com.android.tradefed.testtype.suite.module.Sdk30ModuleController" /> + + <!-- Install test --> + <target_preparer class="com.android.tradefed.targetprep.TestAppInstallSetup"> + <option name="test-file-name" value="SafetyCenterConfigTests.apk" /> + <option name="cleanup-apks" value="true" /> + </target_preparer> + + <test class="com.android.tradefed.testtype.AndroidJUnitTest" > + <option name="package" value="com.android.safetycenter.config.tests" /> + <option name="runner" value="androidx.test.runner.AndroidJUnitRunner" /> + </test> +</configuration> diff --git a/tests/cts/safetycenter/src/android/safetycenter/cts/config/ParseExceptionTest.kt b/SafetyCenter/Config/tests/java/com/android/safetycenter/config/ParseExceptionTest.kt index e805757a7..ca4f914c4 100644 --- a/tests/cts/safetycenter/src/android/safetycenter/cts/config/ParseExceptionTest.kt +++ b/SafetyCenter/Config/tests/java/com/android/safetycenter/config/ParseExceptionTest.kt @@ -14,10 +14,9 @@ * limitations under the License. */ -package android.safetycenter.cts.config +package com.android.safetycenter.config import android.os.Build.VERSION_CODES.TIRAMISU -import android.safetycenter.config.ParseException import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SdkSuppress import com.google.common.truth.Truth.assertThat diff --git a/tests/cts/safetycenter/src/android/safetycenter/cts/config/ParserConfigInvalidTest.kt b/SafetyCenter/Config/tests/java/com/android/safetycenter/config/ParserConfigInvalidTest.kt index ca3d1c7f2..7d8820a3b 100644 --- a/tests/cts/safetycenter/src/android/safetycenter/cts/config/ParserConfigInvalidTest.kt +++ b/SafetyCenter/Config/tests/java/com/android/safetycenter/config/ParserConfigInvalidTest.kt @@ -14,15 +14,13 @@ * limitations under the License. */ -package android.safetycenter.cts.config +package com.android.safetycenter.config import android.content.Context import android.os.Build.VERSION_CODES.TIRAMISU -import android.safetycenter.config.ParseException -import android.safetycenter.config.SafetyCenterConfig -import android.safetycenter.cts.R import androidx.test.core.app.ApplicationProvider.getApplicationContext import androidx.test.filters.SdkSuppress +import com.android.safetycenter.config.tests.R import com.google.common.truth.Truth.assertThat import org.junit.Assert.assertThrows import org.junit.Test @@ -48,9 +46,11 @@ class ParserConfigInvalidTest { @Test fun invalidConfig_throws() { - val parser = context.resources.getXml(params.configResourceId) + val inputStream = context.resources.openRawResource(params.configResourceId) - val thrown = assertThrows(ParseException::class.java) { SafetyCenterConfig.fromXml(parser) } + val thrown = assertThrows(ParseException::class.java) { + SafetyCenterConfigParser.parseXmlResource(inputStream, context.resources) + } assertThat(thrown).hasMessageThat().isEqualTo(params.errorMessage) if (params.causeErrorMessage != null) { @@ -65,315 +65,357 @@ class ParserConfigInvalidTest { arrayOf( Params( "ConfigDynamicSafetySourceAllDisabledNoWork", - R.xml.config_dynamic_safety_source_all_disabled_no_work, + R.raw.config_dynamic_safety_source_all_disabled_no_work, "Element dynamic-safety-source invalid", "Required attribute titleForWork missing" ), Params( "ConfigDynamicSafetySourceAllNoWork", - R.xml.config_dynamic_safety_source_all_no_work, + R.raw.config_dynamic_safety_source_all_no_work, "Element dynamic-safety-source invalid", "Required attribute titleForWork missing" ), Params( "ConfigDynamicSafetySourceDisabledNoSummary", - R.xml.config_dynamic_safety_source_disabled_no_summary, + R.raw.config_dynamic_safety_source_disabled_no_summary, "Element dynamic-safety-source invalid", "Required attribute summary missing" ), Params( "ConfigDynamicSafetySourceDisabledNoTitle", - R.xml.config_dynamic_safety_source_disabled_no_title, + R.raw.config_dynamic_safety_source_disabled_no_title, "Element dynamic-safety-source invalid", "Required attribute title missing" ), Params( "ConfigDynamicSafetySourceDuplicateKey", - R.xml.config_dynamic_safety_source_duplicate_key, + R.raw.config_dynamic_safety_source_duplicate_key, "Element safety-sources-config invalid", "Duplicate id id among safety sources" ), Params( "ConfigDynamicSafetySourceHiddenWithIntent", - R.xml.config_dynamic_safety_source_hidden_with_intent, + R.raw.config_dynamic_safety_source_hidden_with_intent, "Element dynamic-safety-source invalid", "Prohibited attribute intentAction present" ), Params( "ConfigDynamicSafetySourceHiddenWithSummary", - R.xml.config_dynamic_safety_source_hidden_with_summary, + R.raw.config_dynamic_safety_source_hidden_with_summary, "Element dynamic-safety-source invalid", "Prohibited attribute summary present" ), Params( "ConfigDynamicSafetySourceHiddenWithTitle", - R.xml.config_dynamic_safety_source_hidden_with_title, + R.raw.config_dynamic_safety_source_hidden_with_title, "Element dynamic-safety-source invalid", "Prohibited attribute title present" ), Params( "ConfigDynamicSafetySourceInvalidDisplay", - R.xml.config_dynamic_safety_source_invalid_display, + R.raw.config_dynamic_safety_source_invalid_display, "Attribute dynamic-safety-source.initialDisplayState invalid", null ), Params( "ConfigDynamicSafetySourceInvalidProfile", - R.xml.config_dynamic_safety_source_invalid_profile, + R.raw.config_dynamic_safety_source_invalid_profile, "Attribute dynamic-safety-source.profile invalid", null ), Params( "ConfigDynamicSafetySourceNoId", - R.xml.config_dynamic_safety_source_no_id, + R.raw.config_dynamic_safety_source_no_id, "Element dynamic-safety-source invalid", "Required attribute id missing" ), Params( "ConfigDynamicSafetySourceNoIntent", - R.xml.config_dynamic_safety_source_no_intent, + R.raw.config_dynamic_safety_source_no_intent, "Element dynamic-safety-source invalid", "Required attribute intentAction missing" ), Params( "ConfigDynamicSafetySourceNoPackage", - R.xml.config_dynamic_safety_source_no_package, + R.raw.config_dynamic_safety_source_no_package, "Element dynamic-safety-source invalid", "Required attribute packageName missing" ), Params( "ConfigDynamicSafetySourceNoProfile", - R.xml.config_dynamic_safety_source_no_profile, + R.raw.config_dynamic_safety_source_no_profile, "Element dynamic-safety-source invalid", "Required attribute profile missing" ), Params( "ConfigDynamicSafetySourceNoSummary", - R.xml.config_dynamic_safety_source_no_summary, + R.raw.config_dynamic_safety_source_no_summary, "Element dynamic-safety-source invalid", "Required attribute summary missing" ), Params( "ConfigDynamicSafetySourceNoTitle", - R.xml.config_dynamic_safety_source_no_title, + R.raw.config_dynamic_safety_source_no_title, "Element dynamic-safety-source invalid", "Required attribute title missing" ), Params( "ConfigDynamicSafetySourcePrimaryHiddenWithWork", - R.xml.config_dynamic_safety_source_primary_hidden_with_work, + R.raw.config_dynamic_safety_source_primary_hidden_with_work, "Element dynamic-safety-source invalid", "Prohibited attribute titleForWork present" ), Params( "ConfigDynamicSafetySourcePrimaryWithWork", - R.xml.config_dynamic_safety_source_primary_with_work, + R.raw.config_dynamic_safety_source_primary_with_work, "Element dynamic-safety-source invalid", "Prohibited attribute titleForWork present" ), Params( + "ConfigFileCorrupted", + R.raw.config_file_corrupted, + "Exception while parsing the XML resource", + null + ), + Params( "ConfigIssueOnlySafetySourceDuplicateKey", - R.xml.config_issue_only_safety_source_duplicate_key, + R.raw.config_issue_only_safety_source_duplicate_key, "Element safety-sources-config invalid", "Duplicate id id among safety sources" ), Params( "ConfigIssueOnlySafetySourceInvalidProfile", - R.xml.config_issue_only_safety_source_invalid_profile, + R.raw.config_issue_only_safety_source_invalid_profile, "Attribute issue-only-safety-source.profile invalid", null ), Params( "ConfigIssueOnlySafetySourceNoId", - R.xml.config_issue_only_safety_source_no_id, + R.raw.config_issue_only_safety_source_no_id, "Element issue-only-safety-source invalid", "Required attribute id missing" ), Params( "ConfigIssueOnlySafetySourceNoPackage", - R.xml.config_issue_only_safety_source_no_package, + R.raw.config_issue_only_safety_source_no_package, "Element issue-only-safety-source invalid", "Required attribute packageName missing" ), Params( "ConfigIssueOnlySafetySourceNoProfile", - R.xml.config_issue_only_safety_source_no_profile, + R.raw.config_issue_only_safety_source_no_profile, "Element issue-only-safety-source invalid", "Required attribute profile missing" ), Params( "ConfigIssueOnlySafetySourceWithDisplay", - R.xml.config_issue_only_safety_source_with_display, + R.raw.config_issue_only_safety_source_with_display, "Element issue-only-safety-source invalid", "Prohibited attribute initialDisplayState present" ), Params( "ConfigIssueOnlySafetySourceWithIntent", - R.xml.config_issue_only_safety_source_with_intent, + R.raw.config_issue_only_safety_source_with_intent, "Element issue-only-safety-source invalid", "Prohibited attribute intentAction present" ), Params( "ConfigIssueOnlySafetySourceWithSearch", - R.xml.config_issue_only_safety_source_with_search, + R.raw.config_issue_only_safety_source_with_search, "Element issue-only-safety-source invalid", "Prohibited attribute searchTerms present" ), Params( "ConfigIssueOnlySafetySourceWithSummary", - R.xml.config_issue_only_safety_source_with_summary, + R.raw.config_issue_only_safety_source_with_summary, "Element issue-only-safety-source invalid", "Prohibited attribute summary present" ), Params( "ConfigIssueOnlySafetySourceWithTitle", - R.xml.config_issue_only_safety_source_with_title, + R.raw.config_issue_only_safety_source_with_title, "Element issue-only-safety-source invalid", "Prohibited attribute title present" ), Params( "ConfigIssueOnlySafetySourceWithWork", - R.xml.config_issue_only_safety_source_with_work, + R.raw.config_issue_only_safety_source_with_work, "Element issue-only-safety-source invalid", "Prohibited attribute titleForWork present" ), Params( "ConfigMixedSafetySourceDuplicateKey", - R.xml.config_mixed_safety_source_duplicate_key, + R.raw.config_mixed_safety_source_duplicate_key, "Element safety-sources-config invalid", "Duplicate id id among safety sources" ), Params( - "ConfigReferenceInvalid", - R.xml.config_reference_invalid, - "Reference title in safety-sources-group.title missing or invalid", - null - ), - Params( "ConfigSafetyCenterConfigMissing", - R.xml.config_safety_center_config_missing, + R.raw.config_safety_center_config_missing, "Element safety-center-config missing", null ), Params( "ConfigSafetySourcesConfigEmpty", - R.xml.config_safety_sources_config_empty, + R.raw.config_safety_sources_config_empty, "Element safety-sources-config invalid", "No safety sources groups present" ), Params( "ConfigSafetySourcesConfigMissing", - R.xml.config_safety_sources_config_missing, + R.raw.config_safety_sources_config_missing, "Element safety-sources-config missing", null ), Params( "ConfigSafetySourcesGroupDuplicateId", - R.xml.config_safety_sources_group_duplicate_id, + R.raw.config_safety_sources_group_duplicate_id, "Element safety-sources-config invalid", "Duplicate id id among safety sources groups" ), Params( "ConfigSafetySourcesGroupEmpty", - R.xml.config_safety_sources_group_empty, + R.raw.config_safety_sources_group_empty, "Element safety-sources-group invalid", "Safety sources group empty" ), Params( "ConfigSafetySourcesGroupInvalidIcon", - R.xml.config_safety_sources_group_invalid_icon, + R.raw.config_safety_sources_group_invalid_icon, "Attribute safety-sources-group.statelessIconType invalid", null ), Params( "ConfigSafetySourcesGroupNoId", - R.xml.config_safety_sources_group_no_id, + R.raw.config_safety_sources_group_no_id, "Element safety-sources-group invalid", "Required attribute id missing" ), Params( "ConfigSafetySourcesGroupNoTitle", - R.xml.config_safety_sources_group_no_title, + R.raw.config_safety_sources_group_no_title, "Element safety-sources-group invalid", "Required attribute title missing" ), Params( "ConfigStaticSafetySourceDuplicateKey", - R.xml.config_static_safety_source_duplicate_key, + R.raw.config_static_safety_source_duplicate_key, "Element safety-sources-config invalid", "Duplicate id id among safety sources" ), Params( "ConfigStaticSafetySourceInvalidProfile", - R.xml.config_static_safety_source_invalid_profile, + R.raw.config_static_safety_source_invalid_profile, "Attribute static-safety-source.profile invalid", null ), Params( "ConfigStaticSafetySourceNoId", - R.xml.config_static_safety_source_no_id, + R.raw.config_static_safety_source_no_id, "Element static-safety-source invalid", "Required attribute id missing" ), Params( "ConfigStaticSafetySourceNoIntent", - R.xml.config_static_safety_source_no_intent, + R.raw.config_static_safety_source_no_intent, "Element static-safety-source invalid", "Required attribute intentAction missing" ), Params( "ConfigStaticSafetySourceNoProfile", - R.xml.config_static_safety_source_no_profile, + R.raw.config_static_safety_source_no_profile, "Element static-safety-source invalid", "Required attribute profile missing" ), Params( "ConfigStaticSafetySourceNoSummary", - R.xml.config_static_safety_source_no_summary, + R.raw.config_static_safety_source_no_summary, "Element static-safety-source invalid", "Required attribute summary missing" ), Params( "ConfigStaticSafetySourceNoTitle", - R.xml.config_static_safety_source_no_title, + R.raw.config_static_safety_source_no_title, "Element static-safety-source invalid", "Required attribute title missing" ), Params( "ConfigStaticSafetySourceWithDisplay", - R.xml.config_static_safety_source_with_display, + R.raw.config_static_safety_source_with_display, "Element static-safety-source invalid", "Prohibited attribute initialDisplayState present" ), Params( "ConfigStaticSafetySourceWithLogging", - R.xml.config_static_safety_source_with_logging, + R.raw.config_static_safety_source_with_logging, "Element static-safety-source invalid", "Prohibited attribute loggingAllowed present" ), Params( "ConfigStaticSafetySourceWithPackage", - R.xml.config_static_safety_source_with_package, + R.raw.config_static_safety_source_with_package, "Element static-safety-source invalid", "Prohibited attribute packageName present" ), Params( "ConfigStaticSafetySourceWithPrimaryAndWork", - R.xml.config_static_safety_source_with_primary_and_work, + R.raw.config_static_safety_source_with_primary_and_work, "Element static-safety-source invalid", "Prohibited attribute titleForWork present" ), Params( "ConfigStaticSafetySourceWithRefresh", - R.xml.config_static_safety_source_with_refresh, + R.raw.config_static_safety_source_with_refresh, "Element static-safety-source invalid", "Prohibited attribute refreshOnPageOpenAllowed present" ), Params( "ConfigStaticSafetySourceWithSeverity", - R.xml.config_static_safety_source_with_severity, + R.raw.config_static_safety_source_with_severity, "Element static-safety-source invalid", "Prohibited attribute maxSeverityLevel present" + ), + Params( + "ConfigStringResourceNameInvalidEmpty", + R.raw.config_string_resource_name_empty, + "Resource name in safety-sources-group.title cannot be empty", + null + ), + Params( + "ConfigStringResourceNameInvalidNoAt", + R.raw.config_string_resource_name_invalid_no_at, + "Resource name com.android.safetycenter.config.tests:string/reference in " + + "safety-sources-group.title does not start with @", + null + ), + Params( + "ConfigStringResourceNameInvalidNoPackage", + R.raw.config_string_resource_name_invalid_no_package, + "Resource name @string/reference in safety-sources-group.title does not " + + "specify a package", + null + ), + Params( + "ConfigStringResourceNameInvalidNoType", + R.raw.config_string_resource_name_invalid_no_type, + "Resource name @com.android.safetycenter.config.tests:reference in " + + "safety-sources-group.title does not specify a type", + null + ), + Params( + "ConfigStringResourceNameInvalidWrongType", + R.raw.config_string_resource_name_invalid_wrong_type, + "Resource name @com.android.safetycenter.config.tests:raw/" + + "config_string_resource_name_invalid_wrong_type in " + + "safety-sources-group.title is not a string", + null + ), + Params( + "ConfigStringResourceNameMissing", + R.raw.config_string_resource_name_missing, + "Resource name @com.android.safetycenter.config.tests:string/missing in " + + "safety-sources-group.title missing or invalid", + null ) ) } diff --git a/tests/cts/safetycenter/src/android/safetycenter/cts/config/ParserConfigValidTest.kt b/SafetyCenter/Config/tests/java/com/android/safetycenter/config/ParserConfigValidTest.kt index 675ecf95e..9c46baf77 100644 --- a/tests/cts/safetycenter/src/android/safetycenter/cts/config/ParserConfigValidTest.kt +++ b/SafetyCenter/Config/tests/java/com/android/safetycenter/config/ParserConfigValidTest.kt @@ -14,17 +14,17 @@ * limitations under the License. */ -package android.safetycenter.cts.config +package com.android.safetycenter.config import android.content.Context import android.os.Build.VERSION_CODES.TIRAMISU import android.safetycenter.config.SafetyCenterConfig import android.safetycenter.config.SafetySource import android.safetycenter.config.SafetySourcesGroup -import android.safetycenter.cts.R import androidx.test.core.app.ApplicationProvider.getApplicationContext import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SdkSuppress +import com.android.safetycenter.config.tests.R import com.google.common.truth.Truth.assertThat import org.junit.Test import org.junit.runner.RunWith @@ -36,9 +36,9 @@ class ParserConfigValidTest { @Test fun validConfig_matchesExpected() { - val parser = context.resources.getXml(R.xml.config_valid) + val inputStream = context.resources.openRawResource(R.raw.config_valid) - val actual = SafetyCenterConfig.fromXml(parser) + val actual = SafetyCenterConfigParser.parseXmlResource(inputStream, context.resources) val expected = SafetyCenterConfig.Builder() diff --git a/tests/cts/safetycenter/res/xml/config_dynamic_safety_source_all_disabled_no_work.xml b/SafetyCenter/Config/tests/res/raw/config_dynamic_safety_source_all_disabled_no_work.xml index b2594c7ab..7ced767f2 100644 --- a/tests/cts/safetycenter/res/xml/config_dynamic_safety_source_all_disabled_no_work.xml +++ b/SafetyCenter/Config/tests/res/raw/config_dynamic_safety_source_all_disabled_no_work.xml @@ -2,13 +2,13 @@ <safety-sources-config> <safety-sources-group id="id" - title="@string/reference" - summary="@string/reference"> + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference"> <dynamic-safety-source id="id" packageName="package" - title="@string/reference" - summary="@string/reference" + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference" intentAction="intent" profile="all_profiles" initialDisplayState="disabled"/> diff --git a/tests/cts/safetycenter/res/xml/config_dynamic_safety_source_all_no_work.xml b/SafetyCenter/Config/tests/res/raw/config_dynamic_safety_source_all_no_work.xml index e582e0470..ac2757085 100644 --- a/tests/cts/safetycenter/res/xml/config_dynamic_safety_source_all_no_work.xml +++ b/SafetyCenter/Config/tests/res/raw/config_dynamic_safety_source_all_no_work.xml @@ -2,13 +2,13 @@ <safety-sources-config> <safety-sources-group id="id" - title="@string/reference" - summary="@string/reference"> + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference"> <dynamic-safety-source id="id" packageName="package" - title="@string/reference" - summary="@string/reference" + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference" intentAction="intent" profile="all_profiles"/> </safety-sources-group> diff --git a/tests/cts/safetycenter/res/xml/config_dynamic_safety_source_disabled_no_summary.xml b/SafetyCenter/Config/tests/res/raw/config_dynamic_safety_source_disabled_no_summary.xml index 6d065992c..0f87ddece 100644 --- a/tests/cts/safetycenter/res/xml/config_dynamic_safety_source_disabled_no_summary.xml +++ b/SafetyCenter/Config/tests/res/raw/config_dynamic_safety_source_disabled_no_summary.xml @@ -2,12 +2,12 @@ <safety-sources-config> <safety-sources-group id="id" - title="@string/reference" - summary="@string/reference"> + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference"> <dynamic-safety-source id="id" packageName="package" - title="@string/reference" + title="@com.android.safetycenter.config.tests:string/reference" intentAction="intent" profile="primary_profile_only" initialDisplayState="disabled"/> diff --git a/tests/cts/safetycenter/res/xml/config_dynamic_safety_source_disabled_no_title.xml b/SafetyCenter/Config/tests/res/raw/config_dynamic_safety_source_disabled_no_title.xml index 6d535766a..edd47155c 100644 --- a/tests/cts/safetycenter/res/xml/config_dynamic_safety_source_disabled_no_title.xml +++ b/SafetyCenter/Config/tests/res/raw/config_dynamic_safety_source_disabled_no_title.xml @@ -2,12 +2,12 @@ <safety-sources-config> <safety-sources-group id="id" - title="@string/reference" - summary="@string/reference"> + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference"> <dynamic-safety-source id="id" packageName="package" - summary="@string/reference" + summary="@com.android.safetycenter.config.tests:string/reference" intentAction="intent" profile="primary_profile_only" initialDisplayState="disabled"/> diff --git a/tests/cts/safetycenter/res/xml/config_dynamic_safety_source_duplicate_key.xml b/SafetyCenter/Config/tests/res/raw/config_dynamic_safety_source_duplicate_key.xml index be7114d61..20631dbbf 100644 --- a/tests/cts/safetycenter/res/xml/config_dynamic_safety_source_duplicate_key.xml +++ b/SafetyCenter/Config/tests/res/raw/config_dynamic_safety_source_duplicate_key.xml @@ -2,25 +2,25 @@ <safety-sources-config> <safety-sources-group id="id1" - title="@string/reference" - summary="@string/reference"> + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference"> <dynamic-safety-source id="id" packageName="package" - title="@string/reference" - summary="@string/reference" + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference" intentAction="intent" profile="primary_profile_only"/> </safety-sources-group> <safety-sources-group id="id2" - title="@string/reference" - summary="@string/reference"> + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference"> <dynamic-safety-source id="id" packageName="package" - title="@string/reference" - summary="@string/reference" + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference" intentAction="intent" profile="primary_profile_only"/> </safety-sources-group> diff --git a/tests/cts/safetycenter/res/xml/config_dynamic_safety_source_hidden_with_intent.xml b/SafetyCenter/Config/tests/res/raw/config_dynamic_safety_source_hidden_with_intent.xml index b30a6d921..faee1c9e1 100644 --- a/tests/cts/safetycenter/res/xml/config_dynamic_safety_source_hidden_with_intent.xml +++ b/SafetyCenter/Config/tests/res/raw/config_dynamic_safety_source_hidden_with_intent.xml @@ -2,8 +2,8 @@ <safety-sources-config> <safety-sources-group id="id" - title="@string/reference" - summary="@string/reference"> + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference"> <dynamic-safety-source id="id" packageName="package" diff --git a/tests/cts/safetycenter/res/xml/config_dynamic_safety_source_hidden_with_summary.xml b/SafetyCenter/Config/tests/res/raw/config_dynamic_safety_source_hidden_with_summary.xml index c0fd18120..9e9384350 100644 --- a/tests/cts/safetycenter/res/xml/config_dynamic_safety_source_hidden_with_summary.xml +++ b/SafetyCenter/Config/tests/res/raw/config_dynamic_safety_source_hidden_with_summary.xml @@ -2,12 +2,12 @@ <safety-sources-config> <safety-sources-group id="id" - title="@string/reference" - summary="@string/reference"> + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference"> <dynamic-safety-source id="id" packageName="package" - summary="@string/reference" + summary="@com.android.safetycenter.config.tests:string/reference" profile="primary_profile_only" initialDisplayState="hidden"/> </safety-sources-group> diff --git a/tests/cts/safetycenter/res/xml/config_dynamic_safety_source_hidden_with_title.xml b/SafetyCenter/Config/tests/res/raw/config_dynamic_safety_source_hidden_with_title.xml index 190fcdc87..a79f438f7 100644 --- a/tests/cts/safetycenter/res/xml/config_dynamic_safety_source_hidden_with_title.xml +++ b/SafetyCenter/Config/tests/res/raw/config_dynamic_safety_source_hidden_with_title.xml @@ -2,12 +2,12 @@ <safety-sources-config> <safety-sources-group id="id" - title="@string/reference" - summary="@string/reference"> + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference"> <dynamic-safety-source id="id" packageName="package" - title="@string/reference" + title="@com.android.safetycenter.config.tests:string/reference" profile="primary_profile_only" initialDisplayState="hidden"/> </safety-sources-group> diff --git a/tests/cts/safetycenter/res/xml/config_dynamic_safety_source_invalid_display.xml b/SafetyCenter/Config/tests/res/raw/config_dynamic_safety_source_invalid_display.xml index 4c1d00a4c..f2a8b40fb 100644 --- a/tests/cts/safetycenter/res/xml/config_dynamic_safety_source_invalid_display.xml +++ b/SafetyCenter/Config/tests/res/raw/config_dynamic_safety_source_invalid_display.xml @@ -2,13 +2,13 @@ <safety-sources-config> <safety-sources-group id="id" - title="@string/reference" - summary="@string/reference"> + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference"> <dynamic-safety-source id="id" packageName="package" - title="@string/reference" - summary="@string/reference" + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference" intentAction="intent" profile="primary_profile_only" initialDisplayState="invalid"/> diff --git a/tests/cts/safetycenter/res/xml/config_dynamic_safety_source_invalid_profile.xml b/SafetyCenter/Config/tests/res/raw/config_dynamic_safety_source_invalid_profile.xml index 303415b75..85515bcce 100644 --- a/tests/cts/safetycenter/res/xml/config_dynamic_safety_source_invalid_profile.xml +++ b/SafetyCenter/Config/tests/res/raw/config_dynamic_safety_source_invalid_profile.xml @@ -2,13 +2,13 @@ <safety-sources-config> <safety-sources-group id="id" - title="@string/reference" - summary="@string/reference"> + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference"> <dynamic-safety-source id="id" packageName="package" - title="@string/reference" - summary="@string/reference" + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference" intentAction="intent" profile="invalid"/> </safety-sources-group> diff --git a/tests/cts/safetycenter/res/xml/config_dynamic_safety_source_no_id.xml b/SafetyCenter/Config/tests/res/raw/config_dynamic_safety_source_no_id.xml index 8ace4ea4c..93dfbb17c 100644 --- a/tests/cts/safetycenter/res/xml/config_dynamic_safety_source_no_id.xml +++ b/SafetyCenter/Config/tests/res/raw/config_dynamic_safety_source_no_id.xml @@ -2,12 +2,12 @@ <safety-sources-config> <safety-sources-group id="id" - title="@string/reference" - summary="@string/reference"> + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference"> <dynamic-safety-source packageName="package" - title="@string/reference" - summary="@string/reference" + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference" intentAction="intent" profile="primary_profile_only"/> </safety-sources-group> diff --git a/tests/cts/safetycenter/res/xml/config_dynamic_safety_source_no_intent.xml b/SafetyCenter/Config/tests/res/raw/config_dynamic_safety_source_no_intent.xml index 6119e4aca..c7930bf69 100644 --- a/tests/cts/safetycenter/res/xml/config_dynamic_safety_source_no_intent.xml +++ b/SafetyCenter/Config/tests/res/raw/config_dynamic_safety_source_no_intent.xml @@ -2,13 +2,13 @@ <safety-sources-config> <safety-sources-group id="id" - title="@string/reference" - summary="@string/reference"> + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference"> <dynamic-safety-source id="id" packageName="package" - title="@string/reference" - summary="@string/reference" + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference" profile="primary_profile_only"/> </safety-sources-group> </safety-sources-config> diff --git a/tests/cts/safetycenter/res/xml/config_dynamic_safety_source_no_package.xml b/SafetyCenter/Config/tests/res/raw/config_dynamic_safety_source_no_package.xml index 2b40602b5..5c0893d82 100644 --- a/tests/cts/safetycenter/res/xml/config_dynamic_safety_source_no_package.xml +++ b/SafetyCenter/Config/tests/res/raw/config_dynamic_safety_source_no_package.xml @@ -2,12 +2,12 @@ <safety-sources-config> <safety-sources-group id="id" - title="@string/reference" - summary="@string/reference"> + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference"> <dynamic-safety-source id="id" - title="@string/reference" - summary="@string/reference" + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference" intentAction="intent" profile="primary_profile_only"/> </safety-sources-group> diff --git a/tests/cts/safetycenter/res/xml/config_dynamic_safety_source_no_profile.xml b/SafetyCenter/Config/tests/res/raw/config_dynamic_safety_source_no_profile.xml index f54d9400a..b49b9baf0 100644 --- a/tests/cts/safetycenter/res/xml/config_dynamic_safety_source_no_profile.xml +++ b/SafetyCenter/Config/tests/res/raw/config_dynamic_safety_source_no_profile.xml @@ -2,13 +2,13 @@ <safety-sources-config> <safety-sources-group id="id" - title="@string/reference" - summary="@string/reference"> + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference"> <dynamic-safety-source id="id" packageName="package" - title="@string/reference" - summary="@string/reference" + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference" intentAction="intent"/> </safety-sources-group> </safety-sources-config> diff --git a/tests/cts/safetycenter/res/xml/config_dynamic_safety_source_no_summary.xml b/SafetyCenter/Config/tests/res/raw/config_dynamic_safety_source_no_summary.xml index 0683f163a..4c5573618 100644 --- a/tests/cts/safetycenter/res/xml/config_dynamic_safety_source_no_summary.xml +++ b/SafetyCenter/Config/tests/res/raw/config_dynamic_safety_source_no_summary.xml @@ -2,12 +2,12 @@ <safety-sources-config> <safety-sources-group id="id" - title="@string/reference" - summary="@string/reference"> + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference"> <dynamic-safety-source id="id" packageName="package" - title="@string/reference" + title="@com.android.safetycenter.config.tests:string/reference" intentAction="intent" profile="primary_profile_only"/> </safety-sources-group> diff --git a/tests/cts/safetycenter/res/xml/config_dynamic_safety_source_no_title.xml b/SafetyCenter/Config/tests/res/raw/config_dynamic_safety_source_no_title.xml index 84f90e5d9..89c198541 100644 --- a/tests/cts/safetycenter/res/xml/config_dynamic_safety_source_no_title.xml +++ b/SafetyCenter/Config/tests/res/raw/config_dynamic_safety_source_no_title.xml @@ -2,12 +2,12 @@ <safety-sources-config> <safety-sources-group id="id" - title="@string/reference" - summary="@string/reference"> + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference"> <dynamic-safety-source id="id" packageName="package" - summary="@string/reference" + summary="@com.android.safetycenter.config.tests:string/reference" intentAction="intent" profile="primary_profile_only"/> </safety-sources-group> diff --git a/tests/cts/safetycenter/res/xml/config_dynamic_safety_source_primary_hidden_with_work.xml b/SafetyCenter/Config/tests/res/raw/config_dynamic_safety_source_primary_hidden_with_work.xml index ad7add545..b145b8848 100644 --- a/tests/cts/safetycenter/res/xml/config_dynamic_safety_source_primary_hidden_with_work.xml +++ b/SafetyCenter/Config/tests/res/raw/config_dynamic_safety_source_primary_hidden_with_work.xml @@ -2,12 +2,12 @@ <safety-sources-config> <safety-sources-group id="id" - title="@string/reference" - summary="@string/reference"> + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference"> <dynamic-safety-source id="id" packageName="package" - titleForWork="@string/reference" + titleForWork="@com.android.safetycenter.config.tests:string/reference" profile="primary_profile_only" initialDisplayState="hidden"/> </safety-sources-group> diff --git a/SafetyCenter/Config/tests/res/raw/config_dynamic_safety_source_primary_with_work.xml b/SafetyCenter/Config/tests/res/raw/config_dynamic_safety_source_primary_with_work.xml new file mode 100644 index 000000000..48e4de108 --- /dev/null +++ b/SafetyCenter/Config/tests/res/raw/config_dynamic_safety_source_primary_with_work.xml @@ -0,0 +1,17 @@ +<safety-center-config> + <safety-sources-config> + <safety-sources-group + id="id" + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference"> + <dynamic-safety-source + id="id" + packageName="package" + title="@com.android.safetycenter.config.tests:string/reference" + titleForWork="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference" + intentAction="intent" + profile="primary_profile_only"/> + </safety-sources-group> + </safety-sources-config> +</safety-center-config> diff --git a/SafetyCenter/Config/tests/res/raw/config_file_corrupted.txt b/SafetyCenter/Config/tests/res/raw/config_file_corrupted.txt new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/SafetyCenter/Config/tests/res/raw/config_file_corrupted.txt diff --git a/tests/cts/safetycenter/res/xml/config_issue_only_safety_source_duplicate_key.xml b/SafetyCenter/Config/tests/res/raw/config_issue_only_safety_source_duplicate_key.xml index 9c00d5727..9c00d5727 100644 --- a/tests/cts/safetycenter/res/xml/config_issue_only_safety_source_duplicate_key.xml +++ b/SafetyCenter/Config/tests/res/raw/config_issue_only_safety_source_duplicate_key.xml diff --git a/tests/cts/safetycenter/res/xml/config_issue_only_safety_source_invalid_profile.xml b/SafetyCenter/Config/tests/res/raw/config_issue_only_safety_source_invalid_profile.xml index dd85d55a8..dd85d55a8 100644 --- a/tests/cts/safetycenter/res/xml/config_issue_only_safety_source_invalid_profile.xml +++ b/SafetyCenter/Config/tests/res/raw/config_issue_only_safety_source_invalid_profile.xml diff --git a/tests/cts/safetycenter/res/xml/config_issue_only_safety_source_no_id.xml b/SafetyCenter/Config/tests/res/raw/config_issue_only_safety_source_no_id.xml index d57db8e42..d57db8e42 100644 --- a/tests/cts/safetycenter/res/xml/config_issue_only_safety_source_no_id.xml +++ b/SafetyCenter/Config/tests/res/raw/config_issue_only_safety_source_no_id.xml diff --git a/tests/cts/safetycenter/res/xml/config_issue_only_safety_source_no_package.xml b/SafetyCenter/Config/tests/res/raw/config_issue_only_safety_source_no_package.xml index d68b55740..d68b55740 100644 --- a/tests/cts/safetycenter/res/xml/config_issue_only_safety_source_no_package.xml +++ b/SafetyCenter/Config/tests/res/raw/config_issue_only_safety_source_no_package.xml diff --git a/tests/cts/safetycenter/res/xml/config_issue_only_safety_source_no_profile.xml b/SafetyCenter/Config/tests/res/raw/config_issue_only_safety_source_no_profile.xml index 7e7b6ef5f..7e7b6ef5f 100644 --- a/tests/cts/safetycenter/res/xml/config_issue_only_safety_source_no_profile.xml +++ b/SafetyCenter/Config/tests/res/raw/config_issue_only_safety_source_no_profile.xml diff --git a/tests/cts/safetycenter/res/xml/config_issue_only_safety_source_with_display.xml b/SafetyCenter/Config/tests/res/raw/config_issue_only_safety_source_with_display.xml index 1fab83913..1fab83913 100644 --- a/tests/cts/safetycenter/res/xml/config_issue_only_safety_source_with_display.xml +++ b/SafetyCenter/Config/tests/res/raw/config_issue_only_safety_source_with_display.xml diff --git a/tests/cts/safetycenter/res/xml/config_issue_only_safety_source_with_intent.xml b/SafetyCenter/Config/tests/res/raw/config_issue_only_safety_source_with_intent.xml index 9a7fa6bb1..9a7fa6bb1 100644 --- a/tests/cts/safetycenter/res/xml/config_issue_only_safety_source_with_intent.xml +++ b/SafetyCenter/Config/tests/res/raw/config_issue_only_safety_source_with_intent.xml diff --git a/tests/cts/safetycenter/res/xml/config_issue_only_safety_source_with_search.xml b/SafetyCenter/Config/tests/res/raw/config_issue_only_safety_source_with_search.xml index b065a3898..849f35503 100644 --- a/tests/cts/safetycenter/res/xml/config_issue_only_safety_source_with_search.xml +++ b/SafetyCenter/Config/tests/res/raw/config_issue_only_safety_source_with_search.xml @@ -6,7 +6,7 @@ id="id" packageName="package" profile="primary_profile_only" - searchTerms="@string/reference"/> + searchTerms="@com.android.safetycenter.config.tests:string/reference"/> </safety-sources-group> </safety-sources-config> </safety-center-config> diff --git a/tests/cts/safetycenter/res/xml/config_issue_only_safety_source_with_summary.xml b/SafetyCenter/Config/tests/res/raw/config_issue_only_safety_source_with_summary.xml index 7d010018b..04b2ad2a9 100644 --- a/tests/cts/safetycenter/res/xml/config_issue_only_safety_source_with_summary.xml +++ b/SafetyCenter/Config/tests/res/raw/config_issue_only_safety_source_with_summary.xml @@ -6,7 +6,7 @@ id="id" packageName="package" profile="primary_profile_only" - summary="@string/reference"/> + summary="@com.android.safetycenter.config.tests:string/reference"/> </safety-sources-group> </safety-sources-config> </safety-center-config> diff --git a/tests/cts/safetycenter/res/xml/config_issue_only_safety_source_with_title.xml b/SafetyCenter/Config/tests/res/raw/config_issue_only_safety_source_with_title.xml index 3b46eeab7..68d8f1d18 100644 --- a/tests/cts/safetycenter/res/xml/config_issue_only_safety_source_with_title.xml +++ b/SafetyCenter/Config/tests/res/raw/config_issue_only_safety_source_with_title.xml @@ -6,7 +6,7 @@ id="id" packageName="package" profile="primary_profile_only" - title="@string/reference"/> + title="@com.android.safetycenter.config.tests:string/reference"/> </safety-sources-group> </safety-sources-config> </safety-center-config> diff --git a/tests/cts/safetycenter/res/xml/config_issue_only_safety_source_with_work.xml b/SafetyCenter/Config/tests/res/raw/config_issue_only_safety_source_with_work.xml index e50149008..9e0209811 100644 --- a/tests/cts/safetycenter/res/xml/config_issue_only_safety_source_with_work.xml +++ b/SafetyCenter/Config/tests/res/raw/config_issue_only_safety_source_with_work.xml @@ -6,7 +6,7 @@ id="id" packageName="package" profile="all_profiles" - titleForWork="@string/reference"/> + titleForWork="@com.android.safetycenter.config.tests:string/reference"/> </safety-sources-group> </safety-sources-config> </safety-center-config> diff --git a/tests/cts/safetycenter/res/xml/config_mixed_safety_source_duplicate_key.xml b/SafetyCenter/Config/tests/res/raw/config_mixed_safety_source_duplicate_key.xml index e939a9c22..98d10b03b 100644 --- a/tests/cts/safetycenter/res/xml/config_mixed_safety_source_duplicate_key.xml +++ b/SafetyCenter/Config/tests/res/raw/config_mixed_safety_source_duplicate_key.xml @@ -2,23 +2,23 @@ <safety-sources-config> <safety-sources-group id="id1" - title="@string/reference" - summary="@string/reference"> + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference"> <static-safety-source id="id" - title="@string/reference" - summary="@string/reference" + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference" intentAction="intent" profile="primary_profile_only"/> </safety-sources-group> <safety-sources-group id="id2" - title="@string/reference"> + title="@com.android.safetycenter.config.tests:string/reference"> <dynamic-safety-source id="id" packageName="package" - title="@string/reference" - summary="@string/reference" + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference" intentAction="intent" profile="primary_profile_only"/> </safety-sources-group> diff --git a/tests/cts/safetycenter/res/xml/config_safety_center_config_missing.xml b/SafetyCenter/Config/tests/res/raw/config_safety_center_config_missing.xml index 475791691..475791691 100644 --- a/tests/cts/safetycenter/res/xml/config_safety_center_config_missing.xml +++ b/SafetyCenter/Config/tests/res/raw/config_safety_center_config_missing.xml diff --git a/tests/cts/safetycenter/res/xml/config_safety_sources_config_empty.xml b/SafetyCenter/Config/tests/res/raw/config_safety_sources_config_empty.xml index b26ffc008..b26ffc008 100644 --- a/tests/cts/safetycenter/res/xml/config_safety_sources_config_empty.xml +++ b/SafetyCenter/Config/tests/res/raw/config_safety_sources_config_empty.xml diff --git a/tests/cts/safetycenter/res/xml/config_safety_sources_config_missing.xml b/SafetyCenter/Config/tests/res/raw/config_safety_sources_config_missing.xml index 12545759a..12545759a 100644 --- a/tests/cts/safetycenter/res/xml/config_safety_sources_config_missing.xml +++ b/SafetyCenter/Config/tests/res/raw/config_safety_sources_config_missing.xml diff --git a/SafetyCenter/Config/tests/res/raw/config_safety_sources_group_duplicate_id.xml b/SafetyCenter/Config/tests/res/raw/config_safety_sources_group_duplicate_id.xml new file mode 100644 index 000000000..ce2b2f0b8 --- /dev/null +++ b/SafetyCenter/Config/tests/res/raw/config_safety_sources_group_duplicate_id.xml @@ -0,0 +1,26 @@ +<safety-center-config> + <safety-sources-config> + <safety-sources-group + id="id" + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference"> + <static-safety-source + id="id1" + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference" + intentAction="intent" + profile="primary_profile_only"/> + </safety-sources-group> + <safety-sources-group + id="id" + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference"> + <static-safety-source + id="id2" + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference" + intentAction="intent" + profile="primary_profile_only"/> + </safety-sources-group> + </safety-sources-config> +</safety-center-config> diff --git a/tests/cts/safetycenter/res/xml/config_safety_sources_group_empty.xml b/SafetyCenter/Config/tests/res/raw/config_safety_sources_group_empty.xml index a395152f8..5c4d49af9 100644 --- a/tests/cts/safetycenter/res/xml/config_safety_sources_group_empty.xml +++ b/SafetyCenter/Config/tests/res/raw/config_safety_sources_group_empty.xml @@ -2,8 +2,8 @@ <safety-sources-config> <safety-sources-group id="id" - title="@string/reference" - summary="@string/reference"> + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference"> </safety-sources-group> </safety-sources-config> </safety-center-config> diff --git a/SafetyCenter/Config/tests/res/raw/config_safety_sources_group_invalid_icon.xml b/SafetyCenter/Config/tests/res/raw/config_safety_sources_group_invalid_icon.xml new file mode 100644 index 000000000..8a2713a6d --- /dev/null +++ b/SafetyCenter/Config/tests/res/raw/config_safety_sources_group_invalid_icon.xml @@ -0,0 +1,16 @@ +<safety-center-config> + <safety-sources-config> + <safety-sources-group + id="id" + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference" + statelessIconType="invalid"> + <static-safety-source + id="id" + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference" + intentAction="intent" + profile="primary_profile_only"/> + </safety-sources-group> + </safety-sources-config> +</safety-center-config> diff --git a/SafetyCenter/Config/tests/res/raw/config_safety_sources_group_no_id.xml b/SafetyCenter/Config/tests/res/raw/config_safety_sources_group_no_id.xml new file mode 100644 index 000000000..95f86dba8 --- /dev/null +++ b/SafetyCenter/Config/tests/res/raw/config_safety_sources_group_no_id.xml @@ -0,0 +1,14 @@ +<safety-center-config> + <safety-sources-config> + <safety-sources-group + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference"> + <static-safety-source + id="id" + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference" + intentAction="intent" + profile="primary_profile_only"/> + </safety-sources-group> + </safety-sources-config> +</safety-center-config> diff --git a/tests/cts/safetycenter/res/xml/config_safety_sources_group_no_title.xml b/SafetyCenter/Config/tests/res/raw/config_safety_sources_group_no_title.xml index de3ce82b9..9ec249d22 100644 --- a/tests/cts/safetycenter/res/xml/config_safety_sources_group_no_title.xml +++ b/SafetyCenter/Config/tests/res/raw/config_safety_sources_group_no_title.xml @@ -2,12 +2,12 @@ <safety-sources-config> <safety-sources-group id="id" - summary="@string/reference"> + summary="@com.android.safetycenter.config.tests:string/reference"> <dynamic-safety-source id="id" packageName="package" - title="@string/reference" - summary="@string/reference" + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference" intentAction="intent" profile="primary_profile_only"/> </safety-sources-group> diff --git a/SafetyCenter/Config/tests/res/raw/config_static_safety_source_duplicate_key.xml b/SafetyCenter/Config/tests/res/raw/config_static_safety_source_duplicate_key.xml new file mode 100644 index 000000000..2aab748d2 --- /dev/null +++ b/SafetyCenter/Config/tests/res/raw/config_static_safety_source_duplicate_key.xml @@ -0,0 +1,26 @@ +<safety-center-config> + <safety-sources-config> + <safety-sources-group + id="id1" + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference"> + <static-safety-source + id="id" + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference" + intentAction="intent" + profile="primary_profile_only"/> + </safety-sources-group> + <safety-sources-group + id="id2" + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference"> + <static-safety-source + id="id" + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference" + intentAction="intent" + profile="primary_profile_only"/> + </safety-sources-group> + </safety-sources-config> +</safety-center-config> diff --git a/tests/cts/safetycenter/res/xml/config_static_safety_source_invalid_profile.xml b/SafetyCenter/Config/tests/res/raw/config_static_safety_source_invalid_profile.xml index 7c135e782..3c76e45bf 100644 --- a/tests/cts/safetycenter/res/xml/config_static_safety_source_invalid_profile.xml +++ b/SafetyCenter/Config/tests/res/raw/config_static_safety_source_invalid_profile.xml @@ -2,12 +2,12 @@ <safety-sources-config> <safety-sources-group id="id" - title="@string/reference" - summary="@string/reference"> + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference"> <static-safety-source id="id" - title="@string/reference" - summary="@string/reference" + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference" intentAction="intent" profile="invalid"/> </safety-sources-group> diff --git a/SafetyCenter/Config/tests/res/raw/config_static_safety_source_no_id.xml b/SafetyCenter/Config/tests/res/raw/config_static_safety_source_no_id.xml new file mode 100644 index 000000000..9419fa324 --- /dev/null +++ b/SafetyCenter/Config/tests/res/raw/config_static_safety_source_no_id.xml @@ -0,0 +1,14 @@ +<safety-center-config> + <safety-sources-config> + <safety-sources-group + id="id" + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference"> + <static-safety-source + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference" + intentAction="intent" + profile="primary_profile_only"/> + </safety-sources-group> + </safety-sources-config> +</safety-center-config> diff --git a/SafetyCenter/Config/tests/res/raw/config_static_safety_source_no_intent.xml b/SafetyCenter/Config/tests/res/raw/config_static_safety_source_no_intent.xml new file mode 100644 index 000000000..c354e0e02 --- /dev/null +++ b/SafetyCenter/Config/tests/res/raw/config_static_safety_source_no_intent.xml @@ -0,0 +1,14 @@ +<safety-center-config> + <safety-sources-config> + <safety-sources-group + id="id" + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference"> + <static-safety-source + id="id" + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference" + profile="primary_profile_only"/> + </safety-sources-group> + </safety-sources-config> +</safety-center-config> diff --git a/SafetyCenter/Config/tests/res/raw/config_static_safety_source_no_profile.xml b/SafetyCenter/Config/tests/res/raw/config_static_safety_source_no_profile.xml new file mode 100644 index 000000000..5bb4bb0c2 --- /dev/null +++ b/SafetyCenter/Config/tests/res/raw/config_static_safety_source_no_profile.xml @@ -0,0 +1,14 @@ +<safety-center-config> + <safety-sources-config> + <safety-sources-group + id="id" + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference"> + <static-safety-source + id="id" + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference" + intentAction="intent"/> + </safety-sources-group> + </safety-sources-config> +</safety-center-config> diff --git a/tests/cts/safetycenter/res/xml/config_static_safety_source_no_summary.xml b/SafetyCenter/Config/tests/res/raw/config_static_safety_source_no_summary.xml index fa92f0bd8..a79ce63f0 100644 --- a/tests/cts/safetycenter/res/xml/config_static_safety_source_no_summary.xml +++ b/SafetyCenter/Config/tests/res/raw/config_static_safety_source_no_summary.xml @@ -2,11 +2,11 @@ <safety-sources-config> <safety-sources-group id="id" - title="@string/reference" - summary="@string/reference"> + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference"> <static-safety-source id="id" - title="@string/reference" + title="@com.android.safetycenter.config.tests:string/reference" intentAction="intent" profile="primary_profile_only"/> </safety-sources-group> diff --git a/tests/cts/safetycenter/res/xml/config_static_safety_source_no_title.xml b/SafetyCenter/Config/tests/res/raw/config_static_safety_source_no_title.xml index 654a486a5..57e73fbdd 100644 --- a/tests/cts/safetycenter/res/xml/config_static_safety_source_no_title.xml +++ b/SafetyCenter/Config/tests/res/raw/config_static_safety_source_no_title.xml @@ -2,11 +2,11 @@ <safety-sources-config> <safety-sources-group id="id" - title="@string/reference" - summary="@string/reference"> + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference"> <static-safety-source id="id" - summary="@string/reference" + summary="@com.android.safetycenter.config.tests:string/reference" intentAction="intent" profile="primary_profile_only"/> </safety-sources-group> diff --git a/tests/cts/safetycenter/res/xml/config_static_safety_source_with_display.xml b/SafetyCenter/Config/tests/res/raw/config_static_safety_source_with_display.xml index 69c9ca215..40abad35f 100644 --- a/tests/cts/safetycenter/res/xml/config_static_safety_source_with_display.xml +++ b/SafetyCenter/Config/tests/res/raw/config_static_safety_source_with_display.xml @@ -2,12 +2,12 @@ <safety-sources-config> <safety-sources-group id="id" - title="@string/reference" - summary="@string/reference"> + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference"> <static-safety-source id="id" - title="@string/reference" - summary="@string/reference" + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference" intentAction="intent" profile="primary_profile_only" initialDisplayState="disabled"/> diff --git a/tests/cts/safetycenter/res/xml/config_static_safety_source_with_logging.xml b/SafetyCenter/Config/tests/res/raw/config_static_safety_source_with_logging.xml index 090554b1e..25cff1e83 100644 --- a/tests/cts/safetycenter/res/xml/config_static_safety_source_with_logging.xml +++ b/SafetyCenter/Config/tests/res/raw/config_static_safety_source_with_logging.xml @@ -2,12 +2,12 @@ <safety-sources-config> <safety-sources-group id="id" - title="@string/reference" - summary="@string/reference"> + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference"> <static-safety-source id="id" - title="@string/reference" - summary="@string/reference" + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference" intentAction="intent" profile="primary_profile_only" loggingAllowed="false"/> diff --git a/tests/cts/safetycenter/res/xml/config_static_safety_source_with_package.xml b/SafetyCenter/Config/tests/res/raw/config_static_safety_source_with_package.xml index 2a982b4cc..079b29033 100644 --- a/tests/cts/safetycenter/res/xml/config_static_safety_source_with_package.xml +++ b/SafetyCenter/Config/tests/res/raw/config_static_safety_source_with_package.xml @@ -2,12 +2,12 @@ <safety-sources-config> <safety-sources-group id="id" - title="@string/reference" - summary="@string/reference"> + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference"> <static-safety-source id="id" - title="@string/reference" - summary="@string/reference" + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference" intentAction="intent" profile="primary_profile_only" packageName="package"/> diff --git a/SafetyCenter/Config/tests/res/raw/config_static_safety_source_with_primary_and_work.xml b/SafetyCenter/Config/tests/res/raw/config_static_safety_source_with_primary_and_work.xml new file mode 100644 index 000000000..570cf0f81 --- /dev/null +++ b/SafetyCenter/Config/tests/res/raw/config_static_safety_source_with_primary_and_work.xml @@ -0,0 +1,16 @@ +<safety-center-config> + <safety-sources-config> + <safety-sources-group + id="id" + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference"> + <static-safety-source + id="id" + title="@com.android.safetycenter.config.tests:string/reference" + titleForWork="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference" + intentAction="intent" + profile="primary_profile_only"/> + </safety-sources-group> + </safety-sources-config> +</safety-center-config> diff --git a/tests/cts/safetycenter/res/xml/config_static_safety_source_with_refresh.xml b/SafetyCenter/Config/tests/res/raw/config_static_safety_source_with_refresh.xml index caaeee6fb..42114f7ff 100644 --- a/tests/cts/safetycenter/res/xml/config_static_safety_source_with_refresh.xml +++ b/SafetyCenter/Config/tests/res/raw/config_static_safety_source_with_refresh.xml @@ -2,12 +2,12 @@ <safety-sources-config> <safety-sources-group id="id" - title="@string/reference" - summary="@string/reference"> + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference"> <static-safety-source id="id" - title="@string/reference" - summary="@string/reference" + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference" intentAction="intent" profile="primary_profile_only" refreshOnPageOpenAllowed="true"/> diff --git a/tests/cts/safetycenter/res/xml/config_static_safety_source_with_severity.xml b/SafetyCenter/Config/tests/res/raw/config_static_safety_source_with_severity.xml index a9f5d9b89..4fd4ad9fb 100644 --- a/tests/cts/safetycenter/res/xml/config_static_safety_source_with_severity.xml +++ b/SafetyCenter/Config/tests/res/raw/config_static_safety_source_with_severity.xml @@ -2,12 +2,12 @@ <safety-sources-config> <safety-sources-group id="id" - title="@string/reference" - summary="@string/reference"> + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference"> <static-safety-source id="id" - title="@string/reference" - summary="@string/reference" + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference" intentAction="intent" profile="primary_profile_only" maxSeverityLevel="300"/> diff --git a/tests/cts/safetycenter/res/xml/config_reference_invalid.xml b/SafetyCenter/Config/tests/res/raw/config_string_resource_name_empty.xml index 743172994..34884cae3 100644 --- a/tests/cts/safetycenter/res/xml/config_reference_invalid.xml +++ b/SafetyCenter/Config/tests/res/raw/config_string_resource_name_empty.xml @@ -2,12 +2,12 @@ <safety-sources-config> <safety-sources-group id="id" - title="title" - summary="@string/reference"> + title="" + summary="@com.android.safetycenter.config.tests:string/reference"> <static-safety-source id="id" - title="@string/reference" - summary="@string/reference" + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference" intentAction="intent" profile="1"/> </safety-sources-group> diff --git a/SafetyCenter/Config/tests/res/raw/config_string_resource_name_invalid_no_at.xml b/SafetyCenter/Config/tests/res/raw/config_string_resource_name_invalid_no_at.xml new file mode 100644 index 000000000..51fb843a2 --- /dev/null +++ b/SafetyCenter/Config/tests/res/raw/config_string_resource_name_invalid_no_at.xml @@ -0,0 +1,15 @@ +<safety-center-config> + <safety-sources-config> + <safety-sources-group + id="id" + title="com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference"> + <static-safety-source + id="id" + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference" + intentAction="intent" + profile="1"/> + </safety-sources-group> + </safety-sources-config> +</safety-center-config> diff --git a/tests/cts/safetycenter/res/xml/config_safety_sources_group_invalid_icon.xml b/SafetyCenter/Config/tests/res/raw/config_string_resource_name_invalid_no_package.xml index 42b4c47d6..724cb0461 100644 --- a/tests/cts/safetycenter/res/xml/config_safety_sources_group_invalid_icon.xml +++ b/SafetyCenter/Config/tests/res/raw/config_string_resource_name_invalid_no_package.xml @@ -3,14 +3,13 @@ <safety-sources-group id="id" title="@string/reference" - summary="@string/reference" - statelessIconType="invalid"> + summary="@com.android.safetycenter.config.tests:string/reference"> <static-safety-source id="id" - title="@string/reference" - summary="@string/reference" + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference" intentAction="intent" - profile="primary_profile_only"/> + profile="1"/> </safety-sources-group> </safety-sources-config> </safety-center-config> diff --git a/SafetyCenter/Config/tests/res/raw/config_string_resource_name_invalid_no_type.xml b/SafetyCenter/Config/tests/res/raw/config_string_resource_name_invalid_no_type.xml new file mode 100644 index 000000000..e2b7d1a89 --- /dev/null +++ b/SafetyCenter/Config/tests/res/raw/config_string_resource_name_invalid_no_type.xml @@ -0,0 +1,15 @@ +<safety-center-config> + <safety-sources-config> + <safety-sources-group + id="id" + title="@com.android.safetycenter.config.tests:reference" + summary="@com.android.safetycenter.config.tests:string/reference"> + <static-safety-source + id="id" + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference" + intentAction="intent" + profile="1"/> + </safety-sources-group> + </safety-sources-config> +</safety-center-config> diff --git a/SafetyCenter/Config/tests/res/raw/config_string_resource_name_invalid_wrong_type.xml b/SafetyCenter/Config/tests/res/raw/config_string_resource_name_invalid_wrong_type.xml new file mode 100644 index 000000000..4560d1af9 --- /dev/null +++ b/SafetyCenter/Config/tests/res/raw/config_string_resource_name_invalid_wrong_type.xml @@ -0,0 +1,15 @@ +<safety-center-config> + <safety-sources-config> + <safety-sources-group + id="id" + title="@com.android.safetycenter.config.tests:raw/config_string_resource_name_invalid_wrong_type" + summary="@com.android.safetycenter.config.tests:string/reference"> + <static-safety-source + id="id" + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference" + intentAction="intent" + profile="1"/> + </safety-sources-group> + </safety-sources-config> +</safety-center-config> diff --git a/SafetyCenter/Config/tests/res/raw/config_string_resource_name_missing.xml b/SafetyCenter/Config/tests/res/raw/config_string_resource_name_missing.xml new file mode 100644 index 000000000..7be3e9e29 --- /dev/null +++ b/SafetyCenter/Config/tests/res/raw/config_string_resource_name_missing.xml @@ -0,0 +1,15 @@ +<safety-center-config> + <safety-sources-config> + <safety-sources-group + id="id" + title="@com.android.safetycenter.config.tests:string/missing" + summary="@com.android.safetycenter.config.tests:string/reference"> + <static-safety-source + id="id" + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference" + intentAction="intent" + profile="1"/> + </safety-sources-group> + </safety-sources-config> +</safety-center-config> diff --git a/tests/cts/safetycenter/res/xml/config_valid.xml b/SafetyCenter/Config/tests/res/raw/config_valid.xml index 578ea1b72..09c5b93ce 100644 --- a/tests/cts/safetycenter/res/xml/config_valid.xml +++ b/SafetyCenter/Config/tests/res/raw/config_valid.xml @@ -2,34 +2,34 @@ <safety-sources-config> <safety-sources-group id="dynamic" - title="@string/reference" - summary="@string/reference" + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference" statelessIconType="privacy"> <dynamic-safety-source id="dynamic_barebone" packageName="package" - title="@string/reference" - summary="@string/reference" + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference" intentAction="intent" profile="primary_profile_only"/> <dynamic-safety-source id="dynamic_all_optional" packageName="package" - title="@string/reference" - titleForWork="@string/reference" - summary="@string/reference" + title="@com.android.safetycenter.config.tests:string/reference" + titleForWork="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference" intentAction="intent" profile="all_profiles" initialDisplayState="disabled" maxSeverityLevel="300" - searchTerms="@string/reference" + searchTerms="@com.android.safetycenter.config.tests:string/reference" loggingAllowed="false" refreshOnPageOpenAllowed="true"/> <dynamic-safety-source id="dynamic_disabled" packageName="package" - title="@string/reference" - summary="@string/reference" + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference" profile="primary_profile_only" initialDisplayState="disabled"/> <dynamic-safety-source @@ -40,21 +40,21 @@ </safety-sources-group> <safety-sources-group id="static" - title="@string/reference"> + title="@com.android.safetycenter.config.tests:string/reference"> <static-safety-source id="static_barebone" - title="@string/reference" - summary="@string/reference" + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference" intentAction="intent" profile="primary_profile_only"/> <static-safety-source id="static_all_optional" - title="@string/reference" - titleForWork="@string/reference" - summary="@string/reference" + title="@com.android.safetycenter.config.tests:string/reference" + titleForWork="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference" intentAction="intent" profile="all_profiles" - searchTerms="@string/reference"/> + searchTerms="@com.android.safetycenter.config.tests:string/reference"/> </safety-sources-group> <safety-sources-group id="issue_only"> @@ -72,12 +72,12 @@ </safety-sources-group> <safety-sources-group id="mixed" - title="@string/reference"> + title="@com.android.safetycenter.config.tests:string/reference"> <dynamic-safety-source id="mixed_dynamic_barebone" packageName="package" - title="@string/reference" - summary="@string/reference" + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference" intentAction="intent" profile="primary_profile_only"/> <issue-only-safety-source @@ -86,8 +86,8 @@ profile="primary_profile_only"/> <static-safety-source id="mixed_static_barebone" - title="@string/reference" - summary="@string/reference" + title="@com.android.safetycenter.config.tests:string/reference" + summary="@com.android.safetycenter.config.tests:string/reference" intentAction="intent" profile="primary_profile_only"/> </safety-sources-group> diff --git a/tests/cts/safetycenter/res/values/strings.xml b/SafetyCenter/Config/tests/res/values/strings.xml index 8ba7f04a8..8ba7f04a8 100644 --- a/tests/cts/safetycenter/res/values/strings.xml +++ b/SafetyCenter/Config/tests/res/values/strings.xml diff --git a/SafetyCenter/Resources/res/raw/safety_center_config.xml b/SafetyCenter/Resources/res/raw/safety_center_config.xml new file mode 100644 index 000000000..ad891ee48 --- /dev/null +++ b/SafetyCenter/Resources/res/raw/safety_center_config.xml @@ -0,0 +1,48 @@ +<!-- + ~ 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. + --> + +<safety-center-config> + <safety-sources-config> + <!-- TODO(b/214567659): Finalize base XML config --> + <safety-sources-group + id="AndroidLockScreenSources" + title="@com.android.safetycenter.resources:string/lock_screen_sources_title" + summary="@com.android.safetycenter.resources:string/summary_placeholder"> + <dynamic-safety-source + id="AndroidLockScreen" + packageName="com.android.settings" + profile="primary_profile_only" + title="@com.android.safetycenter.resources:string/lock_screen_title" + summary="@com.android.safetycenter.resources:string/lock_screen_summary_disabled" + initialDisplayState="disabled"/> + <dynamic-safety-source + id="AndroidBiometrics" + packageName="com.android.settings" + profile="primary_profile_only" + initialDisplayState="hidden"/> + </safety-sources-group> + <safety-sources-group + id="AndroidAdvancedSources" + title="@com.android.safetycenter.resources:string/advanced_title"> + <static-safety-source + id="AndroidAdvancedSecurity" + profile="primary_profile_only" + intentAction="com.android.settings.security.SECURITY_ADVANCED_SETTINGS" + title="@com.android.safetycenter.resources:string/advanced_security_title" + summary="@com.android.safetycenter.resources:string/advanced_security_summary"/> + </safety-sources-group> + </safety-sources-config> +</safety-center-config> diff --git a/SafetyCenter/Resources/res/values/strings.xml b/SafetyCenter/Resources/res/values/strings.xml index 19a2ccad0..c65313bca 100644 --- a/SafetyCenter/Resources/res/values/strings.xml +++ b/SafetyCenter/Resources/res/values/strings.xml @@ -26,5 +26,10 @@ <string name="lock_screen_title" description="The default title of the setting for managing the screen lock on the device">Screen lock</string> <string name="lock_screen_summary_disabled" description="The default summary of the setting for managing screen lock on the device before the current state is known to safety center">Details available soon</string> + <!-- Advanced --> + <string name="advanced_title" description="TODO">Advanced</string> + <string name="advanced_security_title" description="TODO">Advanced security</string> + <string name="advanced_security_summary" description="TODO">Screen lock, connected apps</string> + <string name="summary_placeholder" description="DO NOT TRANSLATE" translatable="false"> </string> </resources> diff --git a/SafetyCenter/Resources/res/xml/safety_center_config.xml b/SafetyCenter/Resources/res/xml/safety_center_config.xml deleted file mode 100644 index ee555ed86..000000000 --- a/SafetyCenter/Resources/res/xml/safety_center_config.xml +++ /dev/null @@ -1,38 +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. - --> - -<safety-center-config> - <safety-sources-config> - <!-- TODO(b/214567659): Finalize base XML config --> - <safety-sources-group - id="LockScreenSources" - title="@string/lock_screen_sources_title" - summary="@string/summary_placeholder"> - <dynamic-safety-source - profile="primary_profile_only" - title="@string/lock_screen_title" - summary="@string/lock_screen_summary_disabled" - initialDisplayState="disabled" - packageName="com.android.settings" - id="LockScreen"/> - <dynamic-safety-source - profile="primary_profile_only" - packageName="com.android.settings" - initialDisplayState="hidden" - id="Biometrics"/> - </safety-sources-group> - </safety-sources-config> -</safety-center-config> diff --git a/SafetyCenter/ResourcesLib/java/com/android/safetycenter/resources/SafetyCenterResourcesContext.java b/SafetyCenter/ResourcesLib/java/com/android/safetycenter/resources/SafetyCenterResourcesContext.java index 03989efc4..2fa6a1c28 100644 --- a/SafetyCenter/ResourcesLib/java/com/android/safetycenter/resources/SafetyCenterResourcesContext.java +++ b/SafetyCenter/ResourcesLib/java/com/android/safetycenter/resources/SafetyCenterResourcesContext.java @@ -27,12 +27,12 @@ import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.content.res.AssetManager; import android.content.res.Resources; -import android.content.res.XmlResourceParser; import android.util.Log; import com.android.internal.annotations.VisibleForTesting; import java.io.File; +import java.io.InputStream; import java.util.List; /** @@ -152,22 +152,25 @@ public class SafetyCenterResourcesContext extends ContextWrapper { return mResourcesApkPkgName; } - /** Get the Safety Center config XML parser interface from the Safety Center resources APK. */ + /** + * Get the raw XML resource representing the Safety Center configuration from the Safety Center + * resources APK. + */ @Nullable - public XmlResourceParser getSafetyCenterConfig() { - String resoursePkgName = getResourcesApkPkgName(); - if (resoursePkgName == null) { + public InputStream getSafetyCenterConfig() { + String resourcePkgName = getResourcesApkPkgName(); + if (resourcePkgName == null) { return null; } Resources resources = getResources(); if (resources == null) { return null; } - int id = resources.getIdentifier(mConfigName, "xml", resoursePkgName); + int id = resources.getIdentifier(mConfigName, "raw", resourcePkgName); if (id == Resources.ID_NULL) { return null; } - return resources.getXml(id); + return resources.openRawResource(id); } @Nullable diff --git a/SafetyCenter/ResourcesLib/tests/AndroidManifest.xml b/SafetyCenter/ResourcesLib/tests/AndroidManifest.xml index 505505751..471af8d28 100644 --- a/SafetyCenter/ResourcesLib/tests/AndroidManifest.xml +++ b/SafetyCenter/ResourcesLib/tests/AndroidManifest.xml @@ -18,13 +18,13 @@ <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="com.android.safetycenter.tests.resourceslib.safetycenterresourceslib"> + package="com.android.safetycenter.resourceslib.tests"> <application android:label="Safety Center ResourcesLib Tests"> <uses-library android:name="android.test.runner" /> </application> <instrumentation android:name="androidx.test.runner.AndroidJUnitRunner" - android:targetPackage="com.android.safetycenter.tests.resourceslib.safetycenterresourceslib" + android:targetPackage="com.android.safetycenter.resourceslib.tests" android:label="Tests for the Safety Center ResourcesLib library" /> </manifest> diff --git a/SafetyCenter/ResourcesLib/tests/AndroidTest.xml b/SafetyCenter/ResourcesLib/tests/AndroidTest.xml index 840f17d63..75aff0812 100644 --- a/SafetyCenter/ResourcesLib/tests/AndroidTest.xml +++ b/SafetyCenter/ResourcesLib/tests/AndroidTest.xml @@ -30,7 +30,7 @@ </target_preparer> <test class="com.android.tradefed.testtype.AndroidJUnitTest" > - <option name="package" value="com.android.safetycenter.tests.resourceslib.safetycenterresourceslib" /> + <option name="package" value="com.android.safetycenter.resourceslib.tests" /> <option name="runner" value="androidx.test.runner.AndroidJUnitRunner" /> </test> </configuration> diff --git a/SafetyCenter/ResourcesLib/tests/SafetyCenterResourcesLibTestResources/res/raw/test.txt b/SafetyCenter/ResourcesLib/tests/SafetyCenterResourcesLibTestResources/res/raw/test.txt new file mode 100644 index 000000000..3b1246497 --- /dev/null +++ b/SafetyCenter/ResourcesLib/tests/SafetyCenterResourcesLibTestResources/res/raw/test.txt @@ -0,0 +1 @@ +TEST
\ No newline at end of file diff --git a/SafetyCenter/ResourcesLib/tests/SafetyCenterResourcesLibTestResources/res/xml/test.xml b/SafetyCenter/ResourcesLib/tests/SafetyCenterResourcesLibTestResources/res/xml/test.xml deleted file mode 100644 index 52e0a2001..000000000 --- a/SafetyCenter/ResourcesLib/tests/SafetyCenterResourcesLibTestResources/res/xml/test.xml +++ /dev/null @@ -1 +0,0 @@ -<test/>
\ No newline at end of file diff --git a/SafetyCenter/ResourcesLib/tests/java/com/android/safetycenter/resources/SafetyCenterResourcesContextTest.kt b/SafetyCenter/ResourcesLib/tests/java/com/android/safetycenter/resources/SafetyCenterResourcesContextTest.kt index 65a3b72bf..b6fd732a6 100644 --- a/SafetyCenter/ResourcesLib/tests/java/com/android/safetycenter/resources/SafetyCenterResourcesContextTest.kt +++ b/SafetyCenter/ResourcesLib/tests/java/com/android/safetycenter/resources/SafetyCenterResourcesContextTest.kt @@ -25,10 +25,6 @@ import org.junit.Assert.assertNotNull import org.junit.Assert.assertNull import org.junit.Test import org.junit.runner.RunWith -import org.xmlpull.v1.XmlPullParser.END_DOCUMENT -import org.xmlpull.v1.XmlPullParser.END_TAG -import org.xmlpull.v1.XmlPullParser.START_DOCUMENT -import org.xmlpull.v1.XmlPullParser.START_TAG @RunWith(AndroidJUnit4::class) class SafetyCenterResourcesContextTest { @@ -46,17 +42,9 @@ class SafetyCenterResourcesContextTest { assertThat(safetyCenterResourcesContext.resourcesApkPkgName).isEqualTo( RESOURCES_APK_PKG_NAME ) - val parser = safetyCenterResourcesContext.safetyCenterConfig - assertNotNull(parser) - parser?.next() - assertThat(parser?.eventType).isEqualTo(START_DOCUMENT) - parser?.next() - assertThat(parser?.eventType).isEqualTo(START_TAG) - assertThat(parser?.name).isEqualTo(CONFIG_TAG) - parser?.next() - assertThat(parser?.eventType).isEqualTo(END_TAG) - parser?.next() - assertThat(parser?.eventType).isEqualTo(END_DOCUMENT) + val configContent = + safetyCenterResourcesContext.safetyCenterConfig?.bufferedReader().use { it?.readText() } + assertThat(configContent).isEqualTo(CONFIG_CONTENT) assertNotNull(safetyCenterResourcesContext.assets) assertNotNull(safetyCenterResourcesContext.resources) assertNotNull(safetyCenterResourcesContext.theme) @@ -132,6 +120,6 @@ class SafetyCenterResourcesContextTest { const val RESOURCES_APK_PKG_NAME = "com.android.safetycenter.tests.config.safetycenterresourceslibtestresources" const val CONFIG_NAME = "test" - const val CONFIG_TAG = "test" + const val CONFIG_CONTENT = "TEST" } }
\ No newline at end of file diff --git a/framework-s/api/system-current.txt b/framework-s/api/system-current.txt index 483e46165..db2d140ca 100644 --- a/framework-s/api/system-current.txt +++ b/framework-s/api/system-current.txt @@ -425,14 +425,8 @@ package android.safetycenter { package android.safetycenter.config { - public final class ParseException extends java.lang.Exception { - ctor public ParseException(@NonNull String); - ctor public ParseException(@NonNull String, @NonNull Throwable); - } - public final class SafetyCenterConfig implements android.os.Parcelable { method public int describeContents(); - method @NonNull public static android.safetycenter.config.SafetyCenterConfig fromXml(@NonNull android.content.res.XmlResourceParser) throws android.safetycenter.config.ParseException; method @NonNull public java.util.List<android.safetycenter.config.SafetySourcesGroup> getSafetySourcesGroups(); method public void writeToParcel(@NonNull android.os.Parcel, int); field @NonNull public static final android.os.Parcelable.Creator<android.safetycenter.config.SafetyCenterConfig> CREATOR; diff --git a/framework-s/java/android/safetycenter/config/SafetyCenterConfig.java b/framework-s/java/android/safetycenter/config/SafetyCenterConfig.java index 99544e600..e6ee68616 100644 --- a/framework-s/java/android/safetycenter/config/SafetyCenterConfig.java +++ b/framework-s/java/android/safetycenter/config/SafetyCenterConfig.java @@ -23,7 +23,6 @@ import static java.util.Objects.requireNonNull; import android.annotation.NonNull; import android.annotation.SystemApi; -import android.content.res.XmlResourceParser; import android.os.Parcel; import android.os.Parcelable; @@ -71,20 +70,6 @@ public final class SafetyCenterConfig implements Parcelable { mSafetySourcesGroups = safetySourcesGroups; } - /** - * Parses and validates the given XML resource into a {@link SafetyCenterConfig} object. - * - * <p>It throws a {@link ParseException} if the given XML resource does not comply with the - * safety_center_config.xsd schema. - * - * @param parser the XML resource parsing interface - */ - @NonNull - public static SafetyCenterConfig fromXml(@NonNull XmlResourceParser parser) - throws ParseException { - return SafetyCenterConfigParser.parseXmlResource(parser); - } - /** Returns the list of {@link SafetySourcesGroup}s in the configuration. */ @NonNull public List<SafetySourcesGroup> getSafetySourcesGroups() { diff --git a/service/Android.bp b/service/Android.bp index 86e320418..73d240bab 100644 --- a/service/Android.bp +++ b/service/Android.bp @@ -111,6 +111,7 @@ java_sdk_library { //"kotlin-stdlib", "modules-utils-backgroundthread", "modules-utils-os", + "safety-center-config", "safety-center-resources-lib", "service-permission-shared", ], diff --git a/service/java/com/android/safetycenter/SafetyCenterConfigReader.java b/service/java/com/android/safetycenter/SafetyCenterConfigReader.java index 61315a125..109b4b0ac 100644 --- a/service/java/com/android/safetycenter/SafetyCenterConfigReader.java +++ b/service/java/com/android/safetycenter/SafetyCenterConfigReader.java @@ -23,15 +23,17 @@ import android.annotation.Nullable; import android.annotation.StringRes; import android.content.Context; import android.content.res.Resources; -import android.content.res.XmlResourceParser; -import android.safetycenter.config.ParseException; import android.safetycenter.config.SafetyCenterConfig; import android.util.Log; import androidx.annotation.RequiresApi; +import com.android.safetycenter.config.ParseException; +import com.android.safetycenter.config.SafetyCenterConfigParser; import com.android.safetycenter.resources.SafetyCenterResourcesContext; +import java.io.InputStream; + /** * A class that reads the {@link SafetyCenterConfig} from the associated {@link * SafetyCenterResourcesContext}. @@ -100,14 +102,21 @@ final class SafetyCenterConfigReader { @Nullable private SafetyCenterConfig readSafetyCenterConfig() { - XmlResourceParser parser = mSafetyCenterResourcesContext.getSafetyCenterConfig(); - if (parser == null) { + InputStream in = mSafetyCenterResourcesContext.getSafetyCenterConfig(); + if (in == null) { Log.e(TAG, "Cannot get safety center config file"); return null; } + Resources resources = mSafetyCenterResourcesContext.getResources(); + if (resources == null) { + Log.e(TAG, "Cannot get safety center resources"); + return null; + } + try { - SafetyCenterConfig safetyCenterConfig = SafetyCenterConfig.fromXml(parser); + SafetyCenterConfig safetyCenterConfig = + SafetyCenterConfigParser.parseXmlResource(in, resources); Log.i(TAG, "SafetyCenterConfig read successfully"); return safetyCenterConfig; } catch (ParseException e) { diff --git a/tests/cts/safetycenter/Android.bp b/tests/cts/safetycenter/Android.bp index a19827075..82b6e76df 100644 --- a/tests/cts/safetycenter/Android.bp +++ b/tests/cts/safetycenter/Android.bp @@ -39,6 +39,7 @@ android_test { "kotlin-stdlib", "kotlinx-coroutines-android", "kotlin-test", + "safety-center-config", "safety-center-resources-lib", "truth-prebuilt", ], diff --git a/tests/cts/safetycenter/res/xml/config_dynamic_safety_source_primary_with_work.xml b/tests/cts/safetycenter/res/xml/config_dynamic_safety_source_primary_with_work.xml deleted file mode 100644 index 3ecf80264..000000000 --- a/tests/cts/safetycenter/res/xml/config_dynamic_safety_source_primary_with_work.xml +++ /dev/null @@ -1,17 +0,0 @@ -<safety-center-config> - <safety-sources-config> - <safety-sources-group - id="id" - title="@string/reference" - summary="@string/reference"> - <dynamic-safety-source - id="id" - packageName="package" - title="@string/reference" - titleForWork="@string/reference" - summary="@string/reference" - intentAction="intent" - profile="primary_profile_only"/> - </safety-sources-group> - </safety-sources-config> -</safety-center-config> diff --git a/tests/cts/safetycenter/res/xml/config_safety_sources_group_duplicate_id.xml b/tests/cts/safetycenter/res/xml/config_safety_sources_group_duplicate_id.xml deleted file mode 100644 index 0ce73371e..000000000 --- a/tests/cts/safetycenter/res/xml/config_safety_sources_group_duplicate_id.xml +++ /dev/null @@ -1,26 +0,0 @@ -<safety-center-config> - <safety-sources-config> - <safety-sources-group - id="id" - title="@string/reference" - summary="@string/reference"> - <static-safety-source - id="id1" - title="@string/reference" - summary="@string/reference" - intentAction="intent" - profile="primary_profile_only"/> - </safety-sources-group> - <safety-sources-group - id="id" - title="@string/reference" - summary="@string/reference"> - <static-safety-source - id="id2" - title="@string/reference" - summary="@string/reference" - intentAction="intent" - profile="primary_profile_only"/> - </safety-sources-group> - </safety-sources-config> -</safety-center-config> diff --git a/tests/cts/safetycenter/res/xml/config_safety_sources_group_no_id.xml b/tests/cts/safetycenter/res/xml/config_safety_sources_group_no_id.xml deleted file mode 100644 index eaee6731a..000000000 --- a/tests/cts/safetycenter/res/xml/config_safety_sources_group_no_id.xml +++ /dev/null @@ -1,14 +0,0 @@ -<safety-center-config> - <safety-sources-config> - <safety-sources-group - title="@string/reference" - summary="@string/reference"> - <static-safety-source - id="id" - title="@string/reference" - summary="@string/reference" - intentAction="intent" - profile="primary_profile_only"/> - </safety-sources-group> - </safety-sources-config> -</safety-center-config> diff --git a/tests/cts/safetycenter/res/xml/config_static_safety_source_duplicate_key.xml b/tests/cts/safetycenter/res/xml/config_static_safety_source_duplicate_key.xml deleted file mode 100644 index 4fe5e1e65..000000000 --- a/tests/cts/safetycenter/res/xml/config_static_safety_source_duplicate_key.xml +++ /dev/null @@ -1,26 +0,0 @@ -<safety-center-config> - <safety-sources-config> - <safety-sources-group - id="id1" - title="@string/reference" - summary="@string/reference"> - <static-safety-source - id="id" - title="@string/reference" - summary="@string/reference" - intentAction="intent" - profile="primary_profile_only"/> - </safety-sources-group> - <safety-sources-group - id="id2" - title="@string/reference" - summary="@string/reference"> - <static-safety-source - id="id" - title="@string/reference" - summary="@string/reference" - intentAction="intent" - profile="primary_profile_only"/> - </safety-sources-group> - </safety-sources-config> -</safety-center-config> diff --git a/tests/cts/safetycenter/res/xml/config_static_safety_source_no_id.xml b/tests/cts/safetycenter/res/xml/config_static_safety_source_no_id.xml deleted file mode 100644 index 7b919343b..000000000 --- a/tests/cts/safetycenter/res/xml/config_static_safety_source_no_id.xml +++ /dev/null @@ -1,14 +0,0 @@ -<safety-center-config> - <safety-sources-config> - <safety-sources-group - id="id" - title="@string/reference" - summary="@string/reference"> - <static-safety-source - title="@string/reference" - summary="@string/reference" - intentAction="intent" - profile="primary_profile_only"/> - </safety-sources-group> - </safety-sources-config> -</safety-center-config> diff --git a/tests/cts/safetycenter/res/xml/config_static_safety_source_no_intent.xml b/tests/cts/safetycenter/res/xml/config_static_safety_source_no_intent.xml deleted file mode 100644 index 9e97efbc9..000000000 --- a/tests/cts/safetycenter/res/xml/config_static_safety_source_no_intent.xml +++ /dev/null @@ -1,14 +0,0 @@ -<safety-center-config> - <safety-sources-config> - <safety-sources-group - id="id" - title="@string/reference" - summary="@string/reference"> - <static-safety-source - id="id" - title="@string/reference" - summary="@string/reference" - profile="primary_profile_only"/> - </safety-sources-group> - </safety-sources-config> -</safety-center-config> diff --git a/tests/cts/safetycenter/res/xml/config_static_safety_source_no_profile.xml b/tests/cts/safetycenter/res/xml/config_static_safety_source_no_profile.xml deleted file mode 100644 index 32d23c789..000000000 --- a/tests/cts/safetycenter/res/xml/config_static_safety_source_no_profile.xml +++ /dev/null @@ -1,14 +0,0 @@ -<safety-center-config> - <safety-sources-config> - <safety-sources-group - id="id" - title="@string/reference" - summary="@string/reference"> - <static-safety-source - id="id" - title="@string/reference" - summary="@string/reference" - intentAction="intent"/> - </safety-sources-group> - </safety-sources-config> -</safety-center-config> diff --git a/tests/cts/safetycenter/res/xml/config_static_safety_source_with_primary_and_work.xml b/tests/cts/safetycenter/res/xml/config_static_safety_source_with_primary_and_work.xml deleted file mode 100644 index 296e2bc4a..000000000 --- a/tests/cts/safetycenter/res/xml/config_static_safety_source_with_primary_and_work.xml +++ /dev/null @@ -1,16 +0,0 @@ -<safety-center-config> - <safety-sources-config> - <safety-sources-group - id="id" - title="@string/reference" - summary="@string/reference"> - <static-safety-source - id="id" - title="@string/reference" - titleForWork="@string/reference" - summary="@string/reference" - intentAction="intent" - profile="primary_profile_only"/> - </safety-sources-group> - </safety-sources-config> -</safety-center-config> diff --git a/tests/cts/safetycenter/src/android/safetycenter/cts/config/XmlConfigTest.kt b/tests/cts/safetycenter/src/android/safetycenter/cts/config/XmlConfigTest.kt index b3f6bfb12..2becb39f6 100644 --- a/tests/cts/safetycenter/src/android/safetycenter/cts/config/XmlConfigTest.kt +++ b/tests/cts/safetycenter/src/android/safetycenter/cts/config/XmlConfigTest.kt @@ -17,10 +17,10 @@ package android.safetycenter.cts.config import android.os.Build.VERSION_CODES.TIRAMISU -import android.safetycenter.config.SafetyCenterConfig import androidx.test.core.app.ApplicationProvider.getApplicationContext import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SdkSuppress +import com.android.safetycenter.config.SafetyCenterConfigParser import com.android.safetycenter.resources.SafetyCenterResourcesContext import com.google.common.truth.Truth.assertThat import org.junit.Test @@ -34,6 +34,9 @@ class XmlConfigTest { @Test fun safetyCenterConfigResource_validConfig() { // Assert that the parser validates the Safety Center config without throwing any exception - assertThat(SafetyCenterConfig.fromXml(safetyCenterContext.safetyCenterConfig!!)).isNotNull() + assertThat(SafetyCenterConfigParser.parseXmlResource( + safetyCenterContext.safetyCenterConfig!!, + safetyCenterContext.resources!! + )).isNotNull() } } |