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

Commit 7420e1ef authored by Ats Jenk's avatar Ats Jenk Committed by Android (Google) Code Review
Browse files

Merge "Extract helpers for setting up bubble bar bubble" into main

parents f9fa6e46 18c9dc71
Loading
Loading
Loading
Loading
+49 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.wm.shell

import com.android.wm.shell.common.ShellExecutor

/**
 * Simple implementation of [ShellExecutor] that collects all runnables and executes them
 * sequentially once [flushAll] is called
 */
class TestShellExecutor : ShellExecutor {

    private val runnables: MutableList<Runnable> = mutableListOf()

    override fun execute(runnable: Runnable) {
        runnables.add(runnable)
    }

    override fun executeDelayed(runnable: Runnable, delayMillis: Long) {
        execute(runnable)
    }

    override fun removeCallbacks(runnable: Runnable?) {}

    override fun hasCallback(runnable: Runnable?): Boolean = false

    /**
     * Execute all posted runnables sequentially
     */
    fun flushAll() {
        while (runnables.isNotEmpty()) {
            runnables.removeAt(0).run()
        }
    }
}
+7 −30
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import com.android.internal.protolog.ProtoLog
import com.android.internal.statusbar.IStatusBarService
import com.android.wm.shell.Flags
import com.android.wm.shell.ShellTaskOrganizer
import com.android.wm.shell.TestShellExecutor
import com.android.wm.shell.WindowManagerShellWrapper
import com.android.wm.shell.bubbles.Bubbles.SysuiProxy
import com.android.wm.shell.bubbles.properties.ProdBubbleProperties
@@ -41,7 +42,6 @@ import com.android.wm.shell.bubbles.storage.BubblePersistentRepository
import com.android.wm.shell.common.DisplayController
import com.android.wm.shell.common.DisplayInsetsController
import com.android.wm.shell.common.FloatingContentCoordinator
import com.android.wm.shell.common.ShellExecutor
import com.android.wm.shell.common.SyncTransactionQueue
import com.android.wm.shell.common.TaskStackListenerImpl
import com.android.wm.shell.draganddrop.DragAndDropController
@@ -84,16 +84,16 @@ class BubbleControllerBubbleBarTest {
    private lateinit var uiEventLoggerFake: UiEventLoggerFake
    private lateinit var bubblePositioner: BubblePositioner
    private lateinit var bubbleData: BubbleData
    private lateinit var mainExecutor: TestExecutor
    private lateinit var bgExecutor: TestExecutor
    private lateinit var mainExecutor: TestShellExecutor
    private lateinit var bgExecutor: TestShellExecutor

    @Before
    fun setUp() {
        ProtoLog.REQUIRE_PROTOLOGTOOL = false
        ProtoLog.init()

        mainExecutor = TestExecutor()
        bgExecutor = TestExecutor()
        mainExecutor = TestShellExecutor()
        bgExecutor = TestShellExecutor()

        uiEventLoggerFake = UiEventLoggerFake()
        val bubbleLogger = BubbleLogger(uiEventLoggerFake)
@@ -232,8 +232,8 @@ class BubbleControllerBubbleBarTest {
        bubbleData: BubbleData,
        bubbleLogger: BubbleLogger,
        bubblePositioner: BubblePositioner,
        mainExecutor: TestExecutor,
        bgExecutor: TestExecutor,
        mainExecutor: TestShellExecutor,
        bgExecutor: TestShellExecutor,
    ): BubbleController {
        val shellCommandHandler = ShellCommandHandler()
        val shellController =
@@ -289,29 +289,6 @@ class BubbleControllerBubbleBarTest {
        )
    }

    private class TestExecutor : ShellExecutor {

        private val runnables: MutableList<Runnable> = mutableListOf()

        override fun execute(runnable: Runnable) {
            runnables.add(runnable)
        }

        override fun executeDelayed(runnable: Runnable, delayMillis: Long) {
            execute(runnable)
        }

        override fun removeCallbacks(runnable: Runnable?) {}

        override fun hasCallback(runnable: Runnable?): Boolean = false

        fun flushAll() {
            while (runnables.isNotEmpty()) {
                runnables.removeAt(0).run()
            }
        }
    }

    private class FakeBubblesStateListener : Bubbles.BubbleStateListener {
        override fun onBubbleStateChange(update: BubbleBarUpdate?) {}

+7 −57
Original line number Diff line number Diff line
@@ -36,14 +36,11 @@ import com.android.internal.protolog.ProtoLog
import com.android.launcher3.icons.BubbleIconFactory
import com.android.wm.shell.Flags
import com.android.wm.shell.R
import com.android.wm.shell.TestShellExecutor
import com.android.wm.shell.bubbles.Bubbles.SysuiProxy
import com.android.wm.shell.bubbles.animation.AnimatableScaleMatrix
import com.android.wm.shell.common.FloatingContentCoordinator
import com.android.wm.shell.common.ShellExecutor
import com.android.wm.shell.shared.animation.PhysicsAnimatorTestUtils
import com.android.wm.shell.shared.bubbles.BubbleBarLocation
import com.android.wm.shell.taskview.TaskView
import com.android.wm.shell.taskview.TaskViewTaskController
import com.google.common.truth.Truth.assertThat
import com.google.common.util.concurrent.MoreExecutors.directExecutor
import org.junit.After
@@ -71,7 +68,7 @@ class BubbleStackViewTest {
    private lateinit var iconFactory: BubbleIconFactory
    private lateinit var expandedViewManager: FakeBubbleExpandedViewManager
    private lateinit var bubbleStackView: BubbleStackView
    private lateinit var shellExecutor: ShellExecutor
    private lateinit var shellExecutor: TestShellExecutor
    private lateinit var windowManager: WindowManager
    private lateinit var bubbleTaskViewFactory: BubbleTaskViewFactory
    private lateinit var bubbleData: BubbleData
@@ -108,7 +105,7 @@ class BubbleStackViewTest {
            )
        bubbleStackViewManager = FakeBubbleStackViewManager()
        expandedViewManager = FakeBubbleExpandedViewManager()
        bubbleTaskViewFactory = FakeBubbleTaskViewFactory()
        bubbleTaskViewFactory = FakeBubbleTaskViewFactory(context, shellExecutor)
        bubbleStackView =
            BubbleStackView(
                context,
@@ -168,6 +165,7 @@ class BubbleStackViewTest {
            // This will eventually propagate an update back to the stack view, but setting the
            // entire pipeline is outside the scope of a unit test.
            assertThat(bubbleData.isExpanded).isTrue()
            shellExecutor.flushAll()
        }

        assertThat(semaphore.tryAcquire(5, TimeUnit.SECONDS)).isTrue()
@@ -206,6 +204,7 @@ class BubbleStackViewTest {

            bubbleStackView.setSelectedBubble(bubble2)
            bubbleStackView.isExpanded = true
            shellExecutor.flushAll()
        }

        assertThat(semaphore.tryAcquire(5, TimeUnit.SECONDS)).isTrue()
@@ -223,6 +222,7 @@ class BubbleStackViewTest {
        // tap on bubble1 to select it
        InstrumentationRegistry.getInstrumentation().runOnMainSync {
            bubble1.iconView!!.performClick()
            shellExecutor.flushAll()
        }
        assertThat(semaphore.tryAcquire(5, TimeUnit.SECONDS)).isTrue()
        assertThat(bubbleData.selectedBubble).isEqualTo(bubble1)
@@ -233,6 +233,7 @@ class BubbleStackViewTest {
            // listener wired up.
            bubbleStackView.setSelectedBubble(bubble1)
            bubble1.iconView!!.performClick()
            shellExecutor.flushAll()
        }

        assertThat(semaphore.tryAcquire(5, TimeUnit.SECONDS)).isTrue()
@@ -426,55 +427,4 @@ class BubbleStackViewTest {

        override fun hideCurrentInputMethod() {}
    }

    private class TestShellExecutor : ShellExecutor {

        override fun execute(runnable: Runnable) {
            runnable.run()
        }

        override fun executeDelayed(r: Runnable, delayMillis: Long) {
            r.run()
        }

        override fun removeCallbacks(r: Runnable?) {}

        override fun hasCallback(r: Runnable): Boolean = false
    }

    private inner class FakeBubbleTaskViewFactory : BubbleTaskViewFactory {
        override fun create(): BubbleTaskView {
            val taskViewTaskController = mock<TaskViewTaskController>()
            val taskView = TaskView(context, taskViewTaskController)
            return BubbleTaskView(taskView, shellExecutor)
        }
    }

    private inner class FakeBubbleExpandedViewManager : BubbleExpandedViewManager {

        override val overflowBubbles: List<Bubble>
            get() = emptyList()

        override fun setOverflowListener(listener: BubbleData.Listener) {}

        override fun collapseStack() {}

        override fun updateWindowFlagsForBackpress(intercept: Boolean) {}

        override fun promoteBubbleFromOverflow(bubble: Bubble) {}

        override fun removeBubble(key: String, reason: Int) {}

        override fun dismissBubble(bubble: Bubble, reason: Int) {}

        override fun setAppBubbleTaskId(key: String, taskId: Int) {}

        override fun isStackExpanded(): Boolean = false

        override fun isShowingAsBubbleBar(): Boolean = false

        override fun hideCurrentInputMethod() {}

        override fun updateBubbleBarLocation(location: BubbleBarLocation, source: Int) {}
    }
}
+5 −28
Original line number Diff line number Diff line
@@ -35,13 +35,13 @@ import com.android.internal.protolog.ProtoLog
import com.android.internal.statusbar.IStatusBarService
import com.android.launcher3.icons.BubbleIconFactory
import com.android.wm.shell.ShellTaskOrganizer
import com.android.wm.shell.TestShellExecutor
import com.android.wm.shell.WindowManagerShellWrapper
import com.android.wm.shell.bubbles.properties.BubbleProperties
import com.android.wm.shell.bubbles.storage.BubblePersistentRepository
import com.android.wm.shell.common.DisplayController
import com.android.wm.shell.common.DisplayInsetsController
import com.android.wm.shell.common.FloatingContentCoordinator
import com.android.wm.shell.common.ShellExecutor
import com.android.wm.shell.common.SyncTransactionQueue
import com.android.wm.shell.common.TaskStackListenerImpl
import com.android.wm.shell.shared.TransactionPool
@@ -70,8 +70,8 @@ class BubbleViewInfoTaskTest {
    private lateinit var metadataFlagListener: Bubbles.BubbleMetadataFlagListener
    private lateinit var iconFactory: BubbleIconFactory
    private lateinit var bubbleController: BubbleController
    private lateinit var mainExecutor: TestExecutor
    private lateinit var bgExecutor: TestExecutor
    private lateinit var mainExecutor: TestShellExecutor
    private lateinit var bgExecutor: TestShellExecutor
    private lateinit var bubbleStackView: BubbleStackView
    private lateinit var bubblePositioner: BubblePositioner
    private lateinit var bubbleLogger: BubbleLogger
@@ -94,8 +94,8 @@ class BubbleViewInfoTaskTest {
                context.resources.getDimensionPixelSize(R.dimen.importance_ring_stroke_width)
            )

        mainExecutor = TestExecutor()
        bgExecutor = TestExecutor()
        mainExecutor = TestShellExecutor()
        bgExecutor = TestShellExecutor()
        val windowManager = context.getSystemService(WindowManager::class.java)
        val shellInit = ShellInit(mainExecutor)
        val shellCommandHandler = ShellCommandHandler()
@@ -335,27 +335,4 @@ class BubbleViewInfoTaskTest {
            bgExecutor
        )
    }

    private class TestExecutor : ShellExecutor {

        private val runnables: MutableList<Runnable> = mutableListOf()

        override fun execute(runnable: Runnable) {
            runnables.add(runnable)
        }

        override fun executeDelayed(runnable: Runnable, delayMillis: Long) {
            execute(runnable)
        }

        override fun removeCallbacks(runnable: Runnable?) {}

        override fun hasCallback(runnable: Runnable?): Boolean = false

        fun flushAll() {
            while (runnables.isNotEmpty()) {
                runnables.removeAt(0).run()
            }
        }
    }
}
+54 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.wm.shell.bubbles

import com.android.wm.shell.shared.bubbles.BubbleBarLocation
import java.util.Collections

/** Fake implementation of [BubbleExpandedViewManager] for testing. */
class FakeBubbleExpandedViewManager(var bubbleBar: Boolean = false, var expanded: Boolean = false) :
    BubbleExpandedViewManager {

    override val overflowBubbles: List<Bubble>
        get() = Collections.emptyList()

    override fun setOverflowListener(listener: BubbleData.Listener) {}

    override fun collapseStack() {}

    override fun updateWindowFlagsForBackpress(intercept: Boolean) {}

    override fun promoteBubbleFromOverflow(bubble: Bubble) {}

    override fun removeBubble(key: String, reason: Int) {}

    override fun dismissBubble(bubble: Bubble, reason: Int) {}

    override fun setAppBubbleTaskId(key: String, taskId: Int) {}

    override fun isStackExpanded(): Boolean {
        return expanded
    }

    override fun isShowingAsBubbleBar(): Boolean {
        return bubbleBar
    }

    override fun hideCurrentInputMethod() {}

    override fun updateBubbleBarLocation(location: BubbleBarLocation, source: Int) {}
}
Loading