Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7ccea83f authored by Dave Mankoff's avatar Dave Mankoff Committed by Android (Google) Code Review
Browse files

Merge "Ensure that GADLite is destroyed." into tm-dev

parents c8dcc3e7 ec4b69a9
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ import com.android.systemui.util.ViewController
import com.android.systemui.util.settings.GlobalSettings
import javax.inject.Inject
import javax.inject.Named
import javax.inject.Provider

/**
 * Manages [FooterActionsView] behaviour, both when it's placed in QS or QQS (split shade).
@@ -69,7 +70,7 @@ internal class FooterActionsController @Inject constructor(
    private val fgsManagerFooterController: QSFgsManagerFooter,
    private val falsingManager: FalsingManager,
    private val metricsLogger: MetricsLogger,
    private val globalActionsDialog: GlobalActionsDialogLite,
    private val globalActionsDialogProvider: Provider<GlobalActionsDialogLite>,
    private val uiEventLogger: UiEventLogger,
    @Named(PM_LITE_ENABLED) private val showPMLiteButton: Boolean,
    private val globalSetting: GlobalSettings,
@@ -77,6 +78,8 @@ internal class FooterActionsController @Inject constructor(
    private val featureFlags: FeatureFlags
) : ViewController<FooterActionsView>(view) {

    private var globalActionsDialog: GlobalActionsDialogLite? = null

    private var lastExpansion = -1f
    private var listening: Boolean = false

@@ -131,7 +134,7 @@ internal class FooterActionsController @Inject constructor(
            startSettingsActivity()
        } else if (v === powerMenuLite) {
            uiEventLogger.log(GlobalActionsDialogLite.GlobalActionsEvent.GA_OPEN_QS)
            globalActionsDialog.showOrHideDialog(false, true, v)
            globalActionsDialog?.showOrHideDialog(false, true, v)
        }
    }

@@ -158,6 +161,7 @@ internal class FooterActionsController @Inject constructor(

    @VisibleForTesting
    public override fun onViewAttached() {
        globalActionsDialog = globalActionsDialogProvider.get()
        if (showPMLiteButton) {
            powerMenuLite.visibility = View.VISIBLE
            powerMenuLite.setOnClickListener(onClickListener)
@@ -215,6 +219,8 @@ internal class FooterActionsController @Inject constructor(
    }

    override fun onViewDetached() {
        globalActionsDialog?.destroy()
        globalActionsDialog = null
        setListening(false)
        multiUserSetting.isListening = false
    }
+41 −8
Original line number Diff line number Diff line
@@ -33,12 +33,15 @@ import org.mockito.ArgumentMatchers.any
import org.mockito.ArgumentMatchers.anyBoolean
import org.mockito.Mock
import org.mockito.Mockito
import org.mockito.Mockito.never
import org.mockito.Mockito.reset
import org.mockito.Mockito.verify
import org.mockito.MockitoAnnotations
import javax.inject.Provider
import org.mockito.Mockito.`when` as whenever

@SmallTest
@TestableLooper.RunWithLooper
@TestableLooper.RunWithLooper(setAsMainLooper = true)
@RunWith(AndroidTestingRunner::class)
class FooterActionsControllerTest : LeakCheckedTest() {
    @Mock
@@ -56,6 +59,8 @@ class FooterActionsControllerTest : LeakCheckedTest() {
    @Mock
    private lateinit var multiUserSwitchController: MultiUserSwitchController
    @Mock
    private lateinit var globalActionsDialogProvider: Provider<GlobalActionsDialogLite>
    @Mock
    private lateinit var globalActionsDialog: GlobalActionsDialogLite
    @Mock
    private lateinit var uiEventLogger: UiEventLogger
@@ -83,15 +88,11 @@ class FooterActionsControllerTest : LeakCheckedTest() {
        whenever(multiUserSwitchControllerFactory.create(any()))
                .thenReturn(multiUserSwitchController)
        whenever(featureFlags.isEnabled(Flags.NEW_FOOTER)).thenReturn(false)
        whenever(globalActionsDialogProvider.get()).thenReturn(globalActionsDialog)

        view = LayoutInflater.from(context)
                .inflate(R.layout.footer_actions, null) as FooterActionsView
        view = inflateView()

        controller = FooterActionsController(view, multiUserSwitchControllerFactory,
                activityStarter, userManager, userTracker, userInfoController,
                deviceProvisionedController, securityFooterController, fgsManagerController,
                falsingManager, metricsLogger, globalActionsDialog, uiEventLogger,
                showPMLiteButton = true, fakeSettings, Handler(testableLooper.looper), featureFlags)
        controller = constructFooterActionsController(view)
        controller.init()
        ViewUtils.attachView(view)
        // View looper is the testable looper associated with the test
@@ -177,4 +178,36 @@ class FooterActionsControllerTest : LeakCheckedTest() {

        assertThat(multiUserSwitch.visibility).isNotEqualTo(View.VISIBLE)
    }

    @Test
    fun testCleanUpGAD() {
        reset(globalActionsDialogProvider)
        whenever(globalActionsDialogProvider.get()).thenReturn(globalActionsDialog)
        val view = inflateView()
        controller = constructFooterActionsController(view)
        controller.init()
        verify(globalActionsDialogProvider, never()).get()

        // GAD is constructed during attachment
        ViewUtils.attachView(view)
        testableLooper.processAllMessages()
        verify(globalActionsDialogProvider).get()

        ViewUtils.detachView(view)
        testableLooper.processAllMessages()
        verify(globalActionsDialog).destroy()
    }

    private fun inflateView(): FooterActionsView {
        return LayoutInflater.from(context)
                .inflate(R.layout.footer_actions, null) as FooterActionsView
    }

    private fun constructFooterActionsController(view: FooterActionsView): FooterActionsController {
        return FooterActionsController(view, multiUserSwitchControllerFactory,
                activityStarter, userManager, userTracker, userInfoController,
                deviceProvisionedController, securityFooterController, fgsManagerController,
                falsingManager, metricsLogger, globalActionsDialogProvider, uiEventLogger,
                showPMLiteButton = true, fakeSettings, Handler(testableLooper.looper), featureFlags)
    }
}
 No newline at end of file