summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Fabian Kozynski <kozynski@google.com> 2020-05-04 14:21:31 -0400
committer Fabian Kozynski <kozynski@google.com> 2020-05-04 14:24:12 -0400
commit1a4786255957178ea7ebbf2b4356bcf973c761eb (patch)
tree9fc0611a587c1899259512078688a014f4f3f956
parent5ef61d2fe517a88d5c8ade74da8258970905cb99 (diff)
Prevent NPE in ControlsListingControllerImpl
Move initialization of callbacks list to before the ServiceListing is reloaded. That way, it will always be initialized by the time the listener is called. Fixes: 153448765 Test: atest ControlsListingControllerImpl Change-Id: I67ba7f3d4bd74f38d0e6f69857135864dcf4a573
-rw-r--r--packages/SystemUI/src/com/android/systemui/controls/management/ControlsListingControllerImpl.kt5
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/controls/management/ControlsListingControllerImplTest.kt17
2 files changed, 19 insertions, 3 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/controls/management/ControlsListingControllerImpl.kt b/packages/SystemUI/src/com/android/systemui/controls/management/ControlsListingControllerImpl.kt
index 3590f1f4fad8..48f191d12801 100644
--- a/packages/SystemUI/src/com/android/systemui/controls/management/ControlsListingControllerImpl.kt
+++ b/packages/SystemUI/src/com/android/systemui/controls/management/ControlsListingControllerImpl.kt
@@ -66,6 +66,8 @@ class ControlsListingControllerImpl @VisibleForTesting constructor(
)
private var serviceListing = serviceListingBuilder(context)
+ // All operations in background thread
+ private val callbacks = mutableSetOf<ControlsListingController.ControlsListingCallback>()
companion object {
private const val TAG = "ControlsListingControllerImpl"
@@ -116,9 +118,6 @@ class ControlsListingControllerImpl @VisibleForTesting constructor(
}
}
- // All operations in background thread
- private val callbacks = mutableSetOf<ControlsListingController.ControlsListingCallback>()
-
/**
* Adds a callback to this controller.
*
diff --git a/packages/SystemUI/tests/src/com/android/systemui/controls/management/ControlsListingControllerImplTest.kt b/packages/SystemUI/tests/src/com/android/systemui/controls/management/ControlsListingControllerImplTest.kt
index 13a77083255c..9b40c5e87b79 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/controls/management/ControlsListingControllerImplTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/controls/management/ControlsListingControllerImplTest.kt
@@ -38,10 +38,12 @@ import org.mockito.Mock
import org.mockito.Mockito
import org.mockito.Mockito.`when`
import org.mockito.Mockito.inOrder
+import org.mockito.Mockito.mock
import org.mockito.Mockito.never
import org.mockito.Mockito.reset
import org.mockito.Mockito.verify
import org.mockito.MockitoAnnotations
+import java.util.concurrent.Executor
@SmallTest
@RunWith(AndroidTestingRunner::class)
@@ -104,6 +106,21 @@ class ControlsListingControllerImplTest : SysuiTestCase() {
}
@Test
+ fun testImmediateListingReload_doesNotCrash() {
+ val exec = Executor { it.run() }
+ val mockServiceListing = mock(ServiceListing::class.java)
+ var callback: ServiceListing.Callback? = null
+ `when`(mockServiceListing.addCallback(any<ServiceListing.Callback>())).then {
+ callback = it.getArgument(0)
+ Unit
+ }
+ `when`(mockServiceListing.reload()).then {
+ callback?.onServicesReloaded(listOf(serviceInfo))
+ }
+ ControlsListingControllerImpl(mContext, exec, { mockServiceListing })
+ }
+
+ @Test
fun testStartsOnUser() {
assertEquals(user, controller.currentUserId)
}