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

Commit 8de0b907 authored by Mady Mellor's avatar Mady Mellor
Browse files

Move RegionSamplingHelper into WMShell shared

This is used by launcher for gesture nav & bubble bar handle. I wanna
use it for the handle on the bubble bar expanded view, which is in
WMShell. I don't think shell can depend on sysui shared lib since
that lib already depends on shell, so I'm moving this into shell.

Flag: EXEMPT moving a class from sysui to shell
Test: atest RegionSamplingHelperTest
Bug: 353160491
Change-Id: I994cb0f4103ebb9a88262069851aecfd2403d441
parent 88f1c7e6
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@
 * limitations under the License.
 */

package com.android.systemui.shared.navigationbar;
package com.android.wm.shell.shared.handles;

import static android.view.Display.DEFAULT_DISPLAY;

+6 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.wm.shell;
import com.android.wm.shell.common.ShellExecutor;

import java.util.ArrayList;
import java.util.List;

/**
 * Really basic test executor. It just gathers all events in a blob. The only option is to
@@ -52,4 +53,9 @@ public class TestShellExecutor implements ShellExecutor {
            mRunnables.remove(0).run();
        }
    }

    /** Returns the list of callbacks for this executor. */
    public List<Runnable> getCallbacks() {
        return mRunnables;
    }
}
+33 −25
Original line number Diff line number Diff line
@@ -14,7 +14,8 @@
 * limitations under the License.
 */

package com.android.systemui.shared.navigationbar
package com.android.wm.shell.shared.handles


import android.graphics.Rect
import android.testing.TestableLooper.RunWithLooper
@@ -24,16 +25,15 @@ import android.view.ViewRootImpl
import androidx.concurrent.futures.DirectExecutor
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.util.concurrency.FakeExecutor
import com.android.systemui.util.mockito.any
import com.android.systemui.util.mockito.argumentCaptor
import com.android.systemui.util.time.FakeSystemClock
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
import com.android.wm.shell.ShellTestCase
import com.android.wm.shell.TestShellExecutor
import com.google.common.truth.Truth.assertThat
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.ArgumentMatchers.any
import org.mockito.ArgumentMatchers.anyInt
import org.mockito.ArgumentMatchers.eq
import org.mockito.Mock
@@ -42,11 +42,12 @@ import org.mockito.Mockito.never
import org.mockito.Mockito.verify
import org.mockito.Mockito.`when` as whenever
import org.mockito.junit.MockitoJUnit
import org.mockito.kotlin.argumentCaptor

@RunWith(AndroidJUnit4::class)
@SmallTest
@RunWithLooper
class RegionSamplingHelperTest : SysuiTestCase() {
class RegionSamplingHelperTest : ShellTestCase() {

    @Mock
    lateinit var sampledView: View
@@ -72,12 +73,16 @@ class RegionSamplingHelperTest : SysuiTestCase() {
        whenever(surfaceControl.isValid).thenReturn(true)
        whenever(wrappedSurfaceControl.isValid).thenReturn(true)
        whenever(samplingCallback.isSamplingEnabled).thenReturn(true)
        regionSamplingHelper = object : RegionSamplingHelper(sampledView, samplingCallback,
                DirectExecutor.INSTANCE, DirectExecutor.INSTANCE, compositionListener) {
        getInstrumentation().runOnMainSync(Runnable {
            regionSamplingHelper = object : RegionSamplingHelper(
                sampledView, samplingCallback,
                DirectExecutor.INSTANCE, DirectExecutor.INSTANCE, compositionListener
            ) {
                override fun wrap(stopLayerControl: SurfaceControl?): SurfaceControl {
                    return wrappedSurfaceControl
                }
            }
        })
        regionSamplingHelper.setWindowVisible(true)
    }

@@ -112,35 +117,38 @@ class RegionSamplingHelperTest : SysuiTestCase() {
    @Test
    fun testCompositionSamplingListener_has_nonEmptyRect() {
        // simulate race condition
        val fakeExecutor = FakeExecutor(FakeSystemClock()) // pass in as backgroundExecutor
        val fakeExecutor = TestShellExecutor() // pass in as backgroundExecutor
        val fakeSamplingCallback = mock(RegionSamplingHelper.SamplingCallback::class.java)

        whenever(fakeSamplingCallback.isSamplingEnabled).thenReturn(true)
        whenever(wrappedSurfaceControl.isValid).thenReturn(true)

        regionSamplingHelper = object : RegionSamplingHelper(sampledView, fakeSamplingCallback,
                DirectExecutor.INSTANCE, fakeExecutor, compositionListener) {
        getInstrumentation().runOnMainSync(Runnable {
            regionSamplingHelper = object : RegionSamplingHelper(
                sampledView, fakeSamplingCallback,
                DirectExecutor.INSTANCE, fakeExecutor, compositionListener
            ) {
                override fun wrap(stopLayerControl: SurfaceControl?): SurfaceControl {
                    return wrappedSurfaceControl
                }
            }
        })
        regionSamplingHelper.setWindowVisible(true)
        regionSamplingHelper.start(Rect(0, 0, 100, 100))

        // make sure background task is enqueued
        assertThat(fakeExecutor.numPending()).isEqualTo(1)
        assertThat(fakeExecutor.getCallbacks().size).isEqualTo(1)

        // make sure regionSamplingHelper will have empty Rect
        whenever(fakeSamplingCallback.getSampledRegion(any())).thenReturn(Rect(0, 0, 0, 0))
        regionSamplingHelper.onLayoutChange(sampledView, 0, 0, 0, 0, 0, 0, 0, 0)

        // resume running of background thread
        fakeExecutor.runAllReady()
        fakeExecutor.flushAll()

        // grab Rect passed into compositionSamplingListener and make sure it's not empty
        val argumentGrabber = argumentCaptor<Rect>()
        verify(compositionListener).register(any(), anyInt(), eq(wrappedSurfaceControl),
            argumentGrabber.capture())
        assertThat(argumentGrabber.value.isEmpty).isFalse()
        assertThat(argumentGrabber.firstValue.isEmpty).isFalse()
    }
}
 No newline at end of file
+1 −1
Original line number Diff line number Diff line
@@ -140,7 +140,6 @@ import com.android.systemui.settings.UserContextProvider;
import com.android.systemui.settings.UserTracker;
import com.android.systemui.shade.ShadeViewController;
import com.android.systemui.shade.domain.interactor.PanelExpansionInteractor;
import com.android.systemui.shared.navigationbar.RegionSamplingHelper;
import com.android.systemui.shared.recents.utilities.Utilities;
import com.android.systemui.shared.rotation.RotationButtonController;
import com.android.systemui.shared.rotation.RotationPolicyUtil;
@@ -166,6 +165,7 @@ import com.android.systemui.util.DeviceConfigProxy;
import com.android.systemui.util.ViewController;
import com.android.wm.shell.back.BackAnimation;
import com.android.wm.shell.pip.Pip;
import com.android.wm.shell.shared.handles.RegionSamplingHelper;

import dagger.Lazy;