Merge "Fix crash with smartspace view reparenting" into sc-dev

This commit is contained in:
Matt Pietal
2021-05-13 19:12:39 +00:00
committed by Android (Google) Code Review
2 changed files with 13 additions and 8 deletions

View File

@@ -107,7 +107,12 @@ class LockscreenSmartspaceController @Inject constructor(
}
private fun buildView(parent: ViewGroup) {
if (plugin == null || this::view.isInitialized) {
if (plugin == null) {
return
}
if (this::view.isInitialized) {
// Due to some oddities with a singleton smartspace view, allow reparenting
(view.getParent() as ViewGroup?)?.removeView(view)
return
}

View File

@@ -16,7 +16,6 @@
package com.android.systemui.statusbar.lockscreen
import android.app.smartspace.SmartspaceManager
import android.app.smartspace.SmartspaceSession
import android.app.smartspace.SmartspaceSession.OnTargetsAvailableListener
@@ -415,8 +414,9 @@ class LockscreenSmartspaceControllerTest : SysuiTestCase() {
clearInvocations(smartspaceManager)
clearInvocations(plugin)
// WHEN we're asked to connect a second time
controller.buildAndConnectView(fakeParent)
// WHEN we're asked to connect a second time and add to a parent
val view = controller.buildAndConnectView(fakeParent)
fakeParent.addView(view)
// THEN the existing view and session are reused
verify(smartspaceManager, never()).createSmartspaceSession(any())
@@ -424,8 +424,8 @@ class LockscreenSmartspaceControllerTest : SysuiTestCase() {
assertEquals(fakeSmartspaceView, controller.view)
}
private fun connectSession(): View {
val view = controller.buildAndConnectView(fakeParent)
private fun connectSession() {
controller.buildAndConnectView(fakeParent)
verify(smartspaceSession)
.addOnTargetsAvailableListener(any(), capture(sessionListenerCaptor))
@@ -454,7 +454,7 @@ class LockscreenSmartspaceControllerTest : SysuiTestCase() {
verify(fakeSmartspaceView).setDozeAmount(0.5f)
clearInvocations(fakeSmartspaceView)
return view
fakeParent.addView(fakeSmartspaceView)
}
private fun setActiveUser(userHandle: UserHandle) {
@@ -515,4 +515,4 @@ class LockscreenSmartspaceControllerTest : SysuiTestCase() {
}
private const val PRIVATE_LOCKSCREEN_SETTING =
Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS
Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS