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

Commit 659d3330 authored by Annie Lin's avatar Annie Lin
Browse files

Cleanup unused region sampling code for Bubbles.

This is not longer needed since the color of the handle is now set by
BubbleBarCaptionView, which is determined based on the background color
of the Task.

Fix: 403612933
Test: wm presubmit
Flag: com.android.wm.shell.enable_create_any_bubble
Change-Id: I49e6c3776b75f68dcc1c38ab6f6168c7f9e9e945
parent 0a9e09a7
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -53,9 +53,6 @@ class FakeBubbleFactory {
                            false, /* isOverflow */
                            bubble,
                            bubbleTaskView,
                            mainExecutor,
                            bgExecutor,
                            null, /* regionSamplingProvider */
                        )
                    }
            bubble.setViewInfo(createViewInfo(bubbleBarExpandedView))
+0 −151
Original line number Diff line number Diff line
@@ -39,18 +39,15 @@ import com.android.wm.shell.bubbles.BubbleTaskView
import com.android.wm.shell.bubbles.FakeBubbleExpandedViewManager
import com.android.wm.shell.bubbles.FakeBubbleFactory
import com.android.wm.shell.bubbles.FakeBubbleTaskViewFactory
import com.android.wm.shell.bubbles.RegionSamplingProvider
import com.android.wm.shell.bubbles.UiEventSubject.Companion.assertThat
import com.android.wm.shell.common.TestShellExecutor
import com.android.wm.shell.shared.bubbles.DeviceConfig
import com.android.wm.shell.shared.handles.RegionSamplingHelper
import com.google.common.truth.Truth.assertThat
import com.google.common.truth.Truth.assertWithMessage
import org.junit.After
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import java.util.concurrent.Executor

/** Tests for [BubbleBarExpandedViewTest] */
@SmallTest
@@ -74,8 +71,6 @@ class BubbleBarExpandedViewTest {
    private lateinit var bubbleTaskViewFactory: FakeBubbleTaskViewFactory

    private lateinit var bubbleExpandedView: BubbleBarExpandedView
    private var testableRegionSamplingHelper: TestableRegionSamplingHelper? = null
    private var regionSamplingProvider: TestRegionSamplingProvider? = null

    private val uiEventLoggerFake = UiEventLoggerFake()

@@ -104,8 +99,6 @@ class BubbleBarExpandedViewTest {
        bubble = FakeBubbleFactory.createChatBubble(context)
        bubbleTaskView = bubbleTaskViewFactory.create()

        regionSamplingProvider = TestRegionSamplingProvider()

        bubbleExpandedView = LayoutInflater.from(context).inflate(
            R.layout.bubble_bar_expanded_view, null, false /* attachToRoot */
        ) as BubbleBarExpandedView
@@ -116,92 +109,16 @@ class BubbleBarExpandedViewTest {
            false /* isOverflow */,
            bubble,
            bubbleTaskView,
            mainExecutor,
            bgExecutor,
            regionSamplingProvider,
        )

        getInstrumentation().runOnMainSync {
            bubbleExpandedView.onAttachedToWindow()
            // Helper should be created once attached to window
            testableRegionSamplingHelper = regionSamplingProvider!!.helper
        }

        bubbleExpandedView.update(bubble)
    }

    @After
    fun tearDown() {
        testableRegionSamplingHelper?.stopAndDestroy()
        getInstrumentation().waitForIdleSync()
    }

    @Test
    fun testCreateSamplingHelper_onAttach() {
        assertThat(testableRegionSamplingHelper).isNotNull()
    }

    @Test
    fun testDestroySamplingHelper_onDetach() {
        bubbleExpandedView.onDetachedFromWindow()
        assertThat(testableRegionSamplingHelper!!.isDestroyed).isTrue()
    }

    @Test
    fun testStopSampling_onDragStart() {
        bubbleExpandedView.setContentVisibility(true)
        assertThat(testableRegionSamplingHelper!!.isStarted).isTrue()

        bubbleExpandedView.setDragging(true)
        assertThat(testableRegionSamplingHelper!!.isStopped).isTrue()
    }

    @Test
    fun testStartSampling_onDragEnd() {
        bubbleExpandedView.setDragging(true)
        bubbleExpandedView.setContentVisibility(true)
        assertThat(testableRegionSamplingHelper!!.isStopped).isTrue()

        bubbleExpandedView.setDragging(false)
        assertThat(testableRegionSamplingHelper!!.isStarted).isTrue()
    }

    @Test
    fun testStartSampling_onContentVisible() {
        bubbleExpandedView.setContentVisibility(true)
        assertThat(testableRegionSamplingHelper!!.setWindowVisible).isTrue()
        assertThat(testableRegionSamplingHelper!!.isStarted).isTrue()
    }

    @Test
    fun testStopSampling_onContentInvisible() {
        bubbleExpandedView.setContentVisibility(false)

        assertThat(testableRegionSamplingHelper!!.setWindowInvisible).isTrue()
        assertThat(testableRegionSamplingHelper!!.isStopped).isTrue()
    }

    @Test
    fun testSampling_startStopAnimating_visible() {
        bubbleExpandedView.isAnimating = true
        bubbleExpandedView.setContentVisibility(true)
        assertThat(testableRegionSamplingHelper!!.isStopped).isTrue()

        bubbleExpandedView.isAnimating = false
        assertThat(testableRegionSamplingHelper!!.isStarted).isTrue()
    }

    @Test
    fun testSampling_startStopAnimating_invisible() {
        bubbleExpandedView.isAnimating = true
        bubbleExpandedView.setContentVisibility(false)
        assertThat(testableRegionSamplingHelper!!.isStopped).isTrue()
        testableRegionSamplingHelper!!.reset()

        bubbleExpandedView.isAnimating = false
        assertThat(testableRegionSamplingHelper!!.isStopped).isTrue()
    }

    @Test
    fun testEventLogging_dismissBubbleViaAppMenu() {
        getInstrumentation().runOnMainSync { bubbleExpandedView.handleView.performClick() }
@@ -266,9 +183,6 @@ class BubbleBarExpandedViewTest {
            false /* isOverflow */,
            bubble,
            taskView,
            mainExecutor,
            bgExecutor,
            regionSamplingProvider,
        )

        // the task view should be added to the expanded view
@@ -299,9 +213,6 @@ class BubbleBarExpandedViewTest {
            false /* isOverflow */,
            bubble,
            taskView,
            mainExecutor,
            bgExecutor,
            regionSamplingProvider,
        )

        // the task view should be added to the expanded view
@@ -328,66 +239,4 @@ class BubbleBarExpandedViewTest {
        // findViewsWithText returns the TextView, but the click listener is on the parent container
        return views.first().parent as View
    }

    private inner class TestRegionSamplingProvider : RegionSamplingProvider {

        lateinit var helper: TestableRegionSamplingHelper

        override fun createHelper(
            sampledView: View?,
            callback: RegionSamplingHelper.SamplingCallback?,
            backgroundExecutor: Executor?,
            mainExecutor: Executor?
        ): RegionSamplingHelper {
            helper = TestableRegionSamplingHelper(sampledView, callback, backgroundExecutor,
                mainExecutor)
            return helper
        }
    }

    private inner class TestableRegionSamplingHelper(
        sampledView: View?,
        samplingCallback: SamplingCallback?,
        backgroundExecutor: Executor?,
        mainExecutor: Executor?
    ) : RegionSamplingHelper(sampledView, samplingCallback, backgroundExecutor, mainExecutor) {

        var isStarted = false
        var isStopped = false
        var isDestroyed = false
        var setWindowVisible = false
        var setWindowInvisible = false

        override fun start(initialSamplingBounds: Rect) {
            super.start(initialSamplingBounds)
            isStarted = true
        }

        override fun stop() {
            super.stop()
            isStopped = true
        }

        override fun stopAndDestroy() {
            super.stopAndDestroy()
            isDestroyed = true
        }

        override fun setWindowVisible(visible: Boolean) {
            super.setWindowVisible(visible)
            if (visible) {
                setWindowVisible = true
            } else {
                setWindowInvisible = true
            }
        }

        fun reset() {
            isStarted = false
            isStopped = false
            isDestroyed = false
            setWindowVisible = false
            setWindowInvisible = false
        }
    }
}
+0 −3
Original line number Diff line number Diff line
@@ -81,9 +81,6 @@ class BubbleOverflow(private val context: Context, private val positioner: Bubbl
                /* isOverflow= */ true,
                /* bubble= */ null,
                /* bubbleTaskView= */ null,
                /* mainExecutor= */ null,
                /* backgroundExecutor= */ null,
                /* regionSamplingProvider= */ null,
            )
    }

+1 −13
Original line number Diff line number Diff line
@@ -34,7 +34,6 @@ import android.graphics.drawable.Drawable;
import android.util.Log;
import android.util.PathParser;
import android.view.LayoutInflater;
import android.view.View;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.graphics.ColorUtils;
@@ -46,7 +45,6 @@ import com.android.wm.shell.bubbles.appinfo.BubbleAppInfo;
import com.android.wm.shell.bubbles.appinfo.BubbleAppInfoProvider;
import com.android.wm.shell.bubbles.bar.BubbleBarExpandedView;
import com.android.wm.shell.bubbles.bar.BubbleBarLayerView;
import com.android.wm.shell.shared.handles.RegionSamplingHelper;

import java.lang.ref.WeakReference;
import java.util.concurrent.Executor;
@@ -225,17 +223,7 @@ public class BubbleViewInfoTask {
                ProtoLog.v(WM_SHELL_BUBBLES, "Task initializing bubble bar expanded view key=%s",
                        mBubble.getKey());
                viewInfo.bubbleBarExpandedView.initialize(mExpandedViewManager.get(),
                        mPositioner.get(), false /* isOverflow */, mBubble,
                        viewInfo.taskView, mMainExecutor, mBgExecutor,
                        new RegionSamplingProvider() {
                            @Override
                            public RegionSamplingHelper createHelper(View sampledView,
                                    RegionSamplingHelper.SamplingCallback callback,
                                    Executor backgroundExecutor, Executor mainExecutor) {
                                return RegionSamplingProvider.super.createHelper(sampledView,
                                        callback, backgroundExecutor, mainExecutor);
                            }
                        });
                        mPositioner.get(), false /* isOverflow */, mBubble, viewInfo.taskView);
            }
        }

+0 −40
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 android.view.View;

import com.android.wm.shell.shared.handles.RegionSamplingHelper;

import java.util.concurrent.Executor;

/**
 * Wrapper to provide a {@link com.android.wm.shell.shared.handles.RegionSamplingHelper} to allow
 * testing it.
 */
public interface RegionSamplingProvider {

    /** Creates and returns the region sampling helper */
    default RegionSamplingHelper createHelper(View sampledView,
            RegionSamplingHelper.SamplingCallback callback,
            Executor backgroundExecutor,
            Executor mainExecutor) {
        return new RegionSamplingHelper(sampledView,
                callback, backgroundExecutor, mainExecutor);
    }

}
Loading