summaryrefslogtreecommitdiff
path: root/tests/hostside
diff options
context:
space:
mode:
author Max Spencer <maxspencer@google.com> 2023-05-02 13:24:14 +0000
committer Max Spencer <maxspencer@google.com> 2023-05-03 16:24:00 +0000
commit29c5e256a672a12f4639550d4c8c19f750640081 (patch)
tree912919539f4305b83ae3e7c4701842cff72f1141 /tests/hostside
parent24dd787754a68187e683a609ccb4c6340ce5de3b (diff)
Consolidate all SafetySourceStateCollected logging
Removes all the duplication of code and consolidates it in the SafetyCenterDataManager class with substantial reductions in the pull atom callback and the StatsdLogger class. Fix: 277744768 Fix: 277174417 Test: atest SafetyCenterManagerTest Change-Id: I17cd97247566351048e829d89b716a4fa8a17387
Diffstat (limited to 'tests/hostside')
-rw-r--r--tests/hostside/safetycenter/helper-app/src/android/safetycenter/hostside/device/SafetySourceStateCollectedLoggingHelperTests.kt25
-rw-r--r--tests/hostside/safetycenter/src/android/safetycenter/hostside/SafetySourceStateCollectedLoggingHostTest.kt16
2 files changed, 33 insertions, 8 deletions
diff --git a/tests/hostside/safetycenter/helper-app/src/android/safetycenter/hostside/device/SafetySourceStateCollectedLoggingHelperTests.kt b/tests/hostside/safetycenter/helper-app/src/android/safetycenter/hostside/device/SafetySourceStateCollectedLoggingHelperTests.kt
index 52a9750eb..b7bd60d10 100644
--- a/tests/hostside/safetycenter/helper-app/src/android/safetycenter/hostside/device/SafetySourceStateCollectedLoggingHelperTests.kt
+++ b/tests/hostside/safetycenter/helper-app/src/android/safetycenter/hostside/device/SafetySourceStateCollectedLoggingHelperTests.kt
@@ -18,10 +18,13 @@ package android.safetycenter.hostside.device
import android.content.Context
import android.safetycenter.SafetyCenterManager
+import android.safetycenter.SafetyEvent
+import android.safetycenter.SafetySourceErrorDetails
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.android.compatibility.common.util.SystemUtil
import com.android.safetycenter.testing.*
+import com.android.safetycenter.testing.SafetyCenterApisWithShellPermissions.reportSafetySourceErrorWithPermission
import com.android.safetycenter.testing.SafetyCenterTestConfigs.Companion.SOURCE_ID_1
import com.android.safetycenter.testing.SafetyCenterTestConfigs.Companion.SOURCE_ID_2
import com.android.safetycenter.testing.SafetyCenterTestConfigs.Companion.SOURCE_ID_3
@@ -67,6 +70,16 @@ class SafetySourceStateCollectedLoggingHelperTests {
}
@Test
+ fun reportSafetySourceError_source1() {
+ safetyCenterManager.reportSafetySourceErrorWithPermission(
+ SOURCE_ID_1,
+ SafetySourceErrorDetails(
+ SafetyEvent.Builder(SafetyEvent.SAFETY_EVENT_TYPE_SOURCE_STATE_CHANGED).build()
+ )
+ )
+ }
+
+ @Test
fun refreshAllSources_reasonPageOpen_allSuccessful() {
simulateRefresh(
Response.SetData(safetySourceTestData.information),
@@ -89,14 +102,14 @@ class SafetySourceStateCollectedLoggingHelperTests {
@Test
fun refreshAllSources_twiceDifferentData_onlySource1Unchanged() {
simulateRefresh(
- Response.SetData(safetySourceTestData.information),
- Response.SetData(safetySourceTestData.recommendationWithAccountIssue),
- Response.SetData(safetySourceTestData.criticalWithResolvingDeviceIssue)
+ Response.SetData(safetySourceTestData.information),
+ Response.SetData(safetySourceTestData.recommendationWithAccountIssue),
+ Response.SetData(safetySourceTestData.criticalWithResolvingDeviceIssue)
)
simulateRefresh(
- Response.SetData(safetySourceTestData.information),
- Response.SetData(safetySourceTestData.information),
- Response.SetData(safetySourceTestData.information)
+ Response.SetData(safetySourceTestData.information),
+ Response.SetData(safetySourceTestData.information),
+ Response.SetData(safetySourceTestData.information)
)
}
diff --git a/tests/hostside/safetycenter/src/android/safetycenter/hostside/SafetySourceStateCollectedLoggingHostTest.kt b/tests/hostside/safetycenter/src/android/safetycenter/hostside/SafetySourceStateCollectedLoggingHostTest.kt
index 8c00ef35c..22a380e12 100644
--- a/tests/hostside/safetycenter/src/android/safetycenter/hostside/SafetySourceStateCollectedLoggingHostTest.kt
+++ b/tests/hostside/safetycenter/src/android/safetycenter/hostside/SafetySourceStateCollectedLoggingHostTest.kt
@@ -104,6 +104,18 @@ class SafetySourceStateCollectedLoggingHostTest : BaseHostJUnit4Test() {
.containsExactly(SafetySourceStateCollected.CollectionType.SOURCE_UPDATED)
}
+ @Test
+ fun reportSafetySourceError_atomPushedForThatSource() {
+ helperAppRule.runTest(TEST_CLASS_NAME, "reportSafetySourceError_source1")
+
+ val sourceStateAtoms = getSafetySourceStateCollectedAtoms()
+
+ assertThat(sourceStateAtoms.map { it.encodedSafetySourceId })
+ .containsExactly(SOURCE_1_ENCODED_SOURCE_ID)
+ assertThat(sourceStateAtoms.map { it.collectionType })
+ .containsExactly(SafetySourceStateCollected.CollectionType.SOURCE_UPDATED)
+ }
+
private fun getSafetySourceStateCollectedAtoms() =
ReportUtils.getEventMetricDataList(device)
.mapNotNull { it.atom.safetySourceStateCollected }
@@ -113,8 +125,8 @@ class SafetySourceStateCollectedLoggingHostTest : BaseHostJUnit4Test() {
// specifically filter the resultant atoms out using the real encoded source ID.
// Similar failures are also observed on Android Test Hub due to the background
// location source (b/278782808)
- it.encodedSafetySourceId == PLAY_PROTECT_ENCODED_SOURCE_ID
- || it.encodedSafetySourceId == BACKGROUND_LOCATION_ENCODED_SOURCE_ID
+ it.encodedSafetySourceId == PLAY_PROTECT_ENCODED_SOURCE_ID ||
+ it.encodedSafetySourceId == BACKGROUND_LOCATION_ENCODED_SOURCE_ID
}
private companion object {