summaryrefslogtreecommitdiff
path: root/SafetyCenter
diff options
context:
space:
mode:
authorNate Myren <ntmyren@google.com>2023-04-17 12:05:54 -0700
committerNate Myren <ntmyren@google.com>2023-04-24 13:38:41 -0700
commit31f59231a7b86e1f7a0c276b73f32d8cfe348efd (patch)
treef03dd2b0f29bdce6a7ea44a66d31d1ccf727bc0d /SafetyCenter
parentfbf57d89135a9eb394794ddf81eed7b80a518f50 (diff)
downloadPermission-31f59231a7b86e1f7a0c276b73f32d8cfe348efd.tar.gz
Update text and icon of privacy source notifications
This brings the privacy source UX in line with the new spec. Also updatest the Safety Label Change notification to match Fixes: 275734262 Fixes: 279214752 Test: atest NotificationListenerCheckTest, LocationAccessCheckTest Change-Id: I60508d2401025bdda076a145d439b10105baa3d3
Diffstat (limited to 'SafetyCenter')
-rw-r--r--SafetyCenter/Resources/shared_res/values-night/colors.xml20
-rw-r--r--SafetyCenter/Resources/shared_res/values/colors.xml20
-rw-r--r--SafetyCenter/ResourcesLib/java/com/android/safetycenter/resources/SafetyCenterResourcesContext.java47
-rw-r--r--SafetyCenter/ResourcesLib/tests/SafetyCenterResourcesLibTestResources/res/values/colors.xml19
-rw-r--r--SafetyCenter/ResourcesLib/tests/java/com/android/safetycenter/resources/SafetyCenterResourcesContextTest.kt31
5 files changed, 108 insertions, 29 deletions
diff --git a/SafetyCenter/Resources/shared_res/values-night/colors.xml b/SafetyCenter/Resources/shared_res/values-night/colors.xml
new file mode 100644
index 000000000..be7a96628
--- /dev/null
+++ b/SafetyCenter/Resources/shared_res/values-night/colors.xml
@@ -0,0 +1,20 @@
+<!--
+ ~ Copyright (C) 2023 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.
+ -->
+
+<resources>
+ <color name="notification_tint_critical">#EE675C</color>
+ <color name="notification_tint_normal">#8AB4F8</color>
+</resources>
diff --git a/SafetyCenter/Resources/shared_res/values/colors.xml b/SafetyCenter/Resources/shared_res/values/colors.xml
new file mode 100644
index 000000000..ce5e97b40
--- /dev/null
+++ b/SafetyCenter/Resources/shared_res/values/colors.xml
@@ -0,0 +1,20 @@
+<!--
+ ~ Copyright (C) 2023 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.
+ -->
+
+<resources>
+ <color name="notification_tint_critical">#D93025</color>
+ <color name="notification_tint_normal">#1A73E8</color>
+</resources>
diff --git a/SafetyCenter/ResourcesLib/java/com/android/safetycenter/resources/SafetyCenterResourcesContext.java b/SafetyCenter/ResourcesLib/java/com/android/safetycenter/resources/SafetyCenterResourcesContext.java
index 99b236157..7ca257887 100644
--- a/SafetyCenter/ResourcesLib/java/com/android/safetycenter/resources/SafetyCenterResourcesContext.java
+++ b/SafetyCenter/ResourcesLib/java/com/android/safetycenter/resources/SafetyCenterResourcesContext.java
@@ -29,6 +29,7 @@ import android.graphics.drawable.Drawable;
import android.graphics.drawable.Icon;
import android.util.Log;
+import androidx.annotation.ColorInt;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.annotation.VisibleForTesting;
@@ -256,6 +257,10 @@ public class SafetyCenterResourcesContext extends ContextWrapper {
@StringRes
private int getStringRes(String name) {
+ return getResId(name, "string");
+ }
+
+ private int getResId(String name, String type) {
String resourcePkgName = getResourcesApkPkgName();
if (resourcePkgName == null) {
return Resources.ID_NULL;
@@ -266,7 +271,7 @@ public class SafetyCenterResourcesContext extends ContextWrapper {
}
// TODO(b/227738283): profile the performance of this operation and consider adding caching
// or finding some alternative solution.
- return resources.getIdentifier(name, "string", resourcePkgName);
+ return resources.getIdentifier(name, type, resourcePkgName);
}
@Nullable
@@ -329,19 +334,9 @@ public class SafetyCenterResourcesContext extends ContextWrapper {
*/
@Nullable
public Drawable getDrawableByName(String name, @Nullable Resources.Theme theme) {
- String resourcePkgName = getResourcesApkPkgName();
- if (resourcePkgName == null) {
- return null;
- }
-
- Resources resources = getResources();
- if (resources == null) {
- return null;
- }
-
- int resId = resources.getIdentifier(name, "drawable", resourcePkgName);
+ int resId = getResId(name, "drawable");
if (resId != Resources.ID_NULL) {
- return resources.getDrawable(resId, theme);
+ return getResources().getDrawable(resId, theme);
}
if (!mShouldFallbackIfNamedResourceNotFound) {
@@ -358,26 +353,34 @@ public class SafetyCenterResourcesContext extends ContextWrapper {
*/
@Nullable
public Icon getIconByDrawableName(String drawableResName) {
- String packageName = getResourcesApkPkgName();
- if (packageName == null) {
- return null;
+ int resId = getResId(drawableResName, "drawable");
+ if (resId != Resources.ID_NULL) {
+ return Icon.createWithResource(getResourcesApkPkgName(), resId);
}
- Resources resources = getResources();
- if (resources == null) {
- return null;
+ if (!mShouldFallbackIfNamedResourceNotFound) {
+ throw new Resources.NotFoundException();
}
- int resId = resources.getIdentifier(drawableResName, "drawable", packageName);
+ Log.w(TAG, "Drawable resource " + drawableResName + " not found");
+ return null;
+ }
+
+ /**
+ * Gets a color by resource name
+ */
+ @ColorInt
+ public Integer getColorByName(String name) {
+ int resId = getResId(name, "color");
if (resId != Resources.ID_NULL) {
- return Icon.createWithResource(packageName, resId);
+ return getResources().getColor(resId, getTheme());
}
if (!mShouldFallbackIfNamedResourceNotFound) {
throw new Resources.NotFoundException();
}
- Log.w(TAG, "Drawable resource " + drawableResName + " not found");
+ Log.w(TAG, "Color resource " + name + " not found");
return null;
}
}
diff --git a/SafetyCenter/ResourcesLib/tests/SafetyCenterResourcesLibTestResources/res/values/colors.xml b/SafetyCenter/ResourcesLib/tests/SafetyCenterResourcesLibTestResources/res/values/colors.xml
new file mode 100644
index 000000000..709c842cd
--- /dev/null
+++ b/SafetyCenter/ResourcesLib/tests/SafetyCenterResourcesLibTestResources/res/values/colors.xml
@@ -0,0 +1,19 @@
+<!--
+ ~ Copyright (C) 2023 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.
+ -->
+
+<resources>
+ <color name="valid_color">#FFFFFF</color>
+</resources>
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 f7af0c712..1a82460d2 100644
--- a/SafetyCenter/ResourcesLib/tests/java/com/android/safetycenter/resources/SafetyCenterResourcesContextTest.kt
+++ b/SafetyCenter/ResourcesLib/tests/java/com/android/safetycenter/resources/SafetyCenterResourcesContextTest.kt
@@ -182,6 +182,29 @@ class SafetyCenterResourcesContextTest {
}
}
+ @Test
+ fun getColorByName_validColor_returnsColor() {
+ val resourcesContext = createNewResourcesContext()
+
+ assertThat(resourcesContext.getColorByName("valid_color")).isNotNull()
+ }
+
+ @Test
+ fun getColorByName_invalidColorWithFallback_returnsNull() {
+ val resourcesContext = createNewResourcesContext(fallback = true)
+
+ assertThat(resourcesContext.getColorByName("invalid_color")).isNull()
+ }
+
+ @Test
+ fun getColorByName_invalidColorWithoutFallback_throws() {
+ val resourcesContext = createNewResourcesContext(fallback = false)
+
+ assertFailsWith(Resources.NotFoundException::class) {
+ resourcesContext.getColorByName("invalid_color")
+ }
+ }
+
private fun createNewResourcesContext(
resourcesApkAction: String = RESOURCES_APK_ACTION,
resourcesApkPath: String? = null,
@@ -190,13 +213,7 @@ class SafetyCenterResourcesContextTest {
fallback: Boolean = false
) =
SafetyCenterResourcesContext(
- context,
- resourcesApkAction,
- resourcesApkPath,
- configName,
- flags,
- fallback
- )
+ context, resourcesApkAction, resourcesApkPath, configName, flags, fallback)
companion object {
const val RESOURCES_APK_ACTION =