summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Elliot Sisteron <elliotsisteron@google.com> 2023-03-08 14:24:36 +0000
committer Elliot Sisteron <elliotsisteron@google.com> 2023-03-08 14:29:18 +0000
commit830a2cee08646fbd680e897a519cf1ffe52549a4 (patch)
treee295971469b86d567dc1b326ee140e623a23f04f
parent8a4992a73972f3feb17f6518d3dbac2adc05fd90 (diff)
Make overridden default volatile.
To my understanding, the use of a raw static isn't thread safe: go/ej3e-78 > Without synchronization, one thread’s changes might not be visible to other threads. Not only does synchronization prevent threads from observing an object in an inconsistent state, but it ensures that each thread entering a synchronized method or block sees the effects of all previous modifications that were guarded by the same lock. Also renamed `getOptionalString` to `getOptionalStringByName` to match `getStringByName`; and removed a double call to `init` in the constructor. Bug: 269129117 Test: builds Change-Id: I87ee257b9e8ec1822555fb76ad2cdd40a2d3cc86
-rw-r--r--SafetyCenter/ResourcesLib/java/com/android/safetycenter/resources/SafetyCenterResourcesContext.java12
-rw-r--r--SafetyCenter/ResourcesLib/tests/java/com/android/safetycenter/resources/SafetyCenterResourcesContextTest.kt12
-rw-r--r--service/java/com/android/safetycenter/SafetyCenterFlags.java14
-rw-r--r--service/java/com/android/safetycenter/SafetyCenterService.java1
4 files changed, 19 insertions, 20 deletions
diff --git a/SafetyCenter/ResourcesLib/java/com/android/safetycenter/resources/SafetyCenterResourcesContext.java b/SafetyCenter/ResourcesLib/java/com/android/safetycenter/resources/SafetyCenterResourcesContext.java
index 01200ef09..99b236157 100644
--- a/SafetyCenter/ResourcesLib/java/com/android/safetycenter/resources/SafetyCenterResourcesContext.java
+++ b/SafetyCenter/ResourcesLib/java/com/android/safetycenter/resources/SafetyCenterResourcesContext.java
@@ -212,12 +212,6 @@ public class SafetyCenterResourcesContext extends ContextWrapper {
return getString(stringId);
}
- /** Same as {@link #getOptionalString(int)} but using the string name rather than ID. */
- @Nullable
- public String getOptionalString(String name) {
- return getOptionalString(getStringRes(name));
- }
-
/** Same as {@link #getOptionalString(int)} but with the given {@code formatArgs}. */
@Nullable
public String getOptionalString(@StringRes int stringId, Object... formatArgs) {
@@ -227,6 +221,12 @@ public class SafetyCenterResourcesContext extends ContextWrapper {
return getString(stringId, formatArgs);
}
+ /** Same as {@link #getOptionalString(int)} but using the string name rather than ID. */
+ @Nullable
+ public String getOptionalStringByName(String name) {
+ return getOptionalString(getStringRes(name));
+ }
+
/**
* Gets a string resource by name from the Safety Center resources APK, and returns an empty
* string if the resource does not exist (or throws a {@link Resources.NotFoundException} if
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 a4bc87810..f7af0c712 100644
--- a/SafetyCenter/ResourcesLib/tests/java/com/android/safetycenter/resources/SafetyCenterResourcesContextTest.kt
+++ b/SafetyCenter/ResourcesLib/tests/java/com/android/safetycenter/resources/SafetyCenterResourcesContextTest.kt
@@ -116,24 +116,24 @@ class SafetyCenterResourcesContextTest {
}
@Test
- fun getOptionalString_validString_returnsString() {
+ fun getOptionalStringByName_validString_returnsString() {
val resourcesContext = createNewResourcesContext()
- assertThat(resourcesContext.getOptionalString("valid_string")).isEqualTo("I exist!")
+ assertThat(resourcesContext.getOptionalStringByName("valid_string")).isEqualTo("I exist!")
}
@Test
- fun getOptionalString_invalidStringWithFallback_returnsNull() {
+ fun getOptionalStringByName_invalidStringWithFallback_returnsNull() {
val resourcesContext = createNewResourcesContext(fallback = true)
- assertThat(resourcesContext.getOptionalString("invalid_string")).isNull()
+ assertThat(resourcesContext.getOptionalStringByName("invalid_string")).isNull()
}
@Test
- fun getOptionalString_invalidStringWithoutFallback_returnsNull() {
+ fun getOptionalStringByName_invalidStringWithoutFallback_returnsNull() {
val resourcesContext = createNewResourcesContext(fallback = false)
- assertThat(resourcesContext.getOptionalString("invalid_string")).isNull()
+ assertThat(resourcesContext.getOptionalStringByName("invalid_string")).isNull()
}
@Test
diff --git a/service/java/com/android/safetycenter/SafetyCenterFlags.java b/service/java/com/android/safetycenter/SafetyCenterFlags.java
index c18209acc..5e77bebc6 100644
--- a/service/java/com/android/safetycenter/SafetyCenterFlags.java
+++ b/service/java/com/android/safetycenter/SafetyCenterFlags.java
@@ -113,8 +113,6 @@ public final class SafetyCenterFlags {
private static final Duration NOTIFICATIONS_MIN_DELAY_DEFAULT_DURATION = Duration.ofDays(180);
- private static String sIssueCategoryAllowlistDefault = "";
-
private static final String REFRESH_SOURCES_TIMEOUT_DEFAULT =
"100:15000,200:60000,300:30000,400:30000,500:30000,600:3600000";
private static final Duration REFRESH_SOURCES_TIMEOUT_DEFAULT_DURATION = Duration.ofSeconds(15);
@@ -125,25 +123,27 @@ public final class SafetyCenterFlags {
private static final String RESURFACE_ISSUE_DELAYS_DEFAULT = "";
private static final Duration RESURFACE_ISSUE_DELAYS_DEFAULT_DURATION = Duration.ofDays(180);
- private static String sUntrackedSourcesDefault =
+ private static volatile String sUntrackedSourcesDefault =
"AndroidAccessibility,AndroidBackgroundLocation,"
+ "AndroidNotificationListener,AndroidPermissionAutoRevoke";
- private static String sBackgroundRefreshDenyDefault = "";
+ private static volatile String sBackgroundRefreshDenyDefault = "";
+
+ private static volatile String sIssueCategoryAllowlistDefault = "";
static void init(SafetyCenterResourcesContext resourceContext) {
String untrackedSourcesDefault =
- resourceContext.getOptionalString("config_defaultUntrackedSources");
+ resourceContext.getOptionalStringByName("config_defaultUntrackedSources");
if (untrackedSourcesDefault != null) {
sUntrackedSourcesDefault = untrackedSourcesDefault;
}
String backgroundRefreshDenyDefault =
- resourceContext.getOptionalString("config_defaultBackgroundRefreshDeny");
+ resourceContext.getOptionalStringByName("config_defaultBackgroundRefreshDeny");
if (backgroundRefreshDenyDefault != null) {
sBackgroundRefreshDenyDefault = backgroundRefreshDenyDefault;
}
String issueCategoryAllowlistDefault =
- resourceContext.getOptionalString("config_defaultIssueCategoryAllowlist");
+ resourceContext.getOptionalStringByName("config_defaultIssueCategoryAllowlist");
if (issueCategoryAllowlistDefault != null) {
sIssueCategoryAllowlistDefault = issueCategoryAllowlistDefault;
}
diff --git a/service/java/com/android/safetycenter/SafetyCenterService.java b/service/java/com/android/safetycenter/SafetyCenterService.java
index 47ec0e4bd..a84c2a4f1 100644
--- a/service/java/com/android/safetycenter/SafetyCenterService.java
+++ b/service/java/com/android/safetycenter/SafetyCenterService.java
@@ -146,7 +146,6 @@ public final class SafetyCenterService extends SystemService {
public SafetyCenterService(Context context) {
super(context);
mSafetyCenterResourcesContext = new SafetyCenterResourcesContext(context);
- SafetyCenterFlags.init(mSafetyCenterResourcesContext);
mSafetyCenterConfigReader = new SafetyCenterConfigReader(mSafetyCenterResourcesContext);
mSafetyCenterStatsdLogger =
new SafetyCenterStatsdLogger(context, mSafetyCenterConfigReader);