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

Commit 2a5d5da9 authored by Nataniel Borges's avatar Nataniel Borges Committed by Android (Google) Code Review
Browse files

Merge "[DO NOT MERGE] Compatibilize flicker from master to sc-v2-dev" into sc-v2-dev

parents d8b856ce 2af16463
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -42,6 +42,9 @@
    <uses-permission android:name="android.permission.MEDIA_CONTENT_CONTROL"/>
    <!-- ATM.removeRootTasksWithActivityTypes() -->
    <uses-permission android:name="android.permission.MANAGE_ACTIVITY_TASKS" />
    <!-- Enable bubble notification-->
    <uses-permission android:name="android.permission.STATUS_BAR_SERVICE" />

    <!-- Allow the test to write directly to /sdcard/ -->
    <application android:requestLegacyExternalStorage="true">
        <uses-library android:name="android.test.runner"/>
+2 −10
Original line number Diff line number Diff line
@@ -20,13 +20,11 @@ import android.app.Instrumentation
import android.content.Context
import android.platform.test.annotations.Presubmit
import android.system.helpers.ActivityHelper
import android.view.Surface
import androidx.test.filters.FlakyTest
import androidx.test.platform.app.InstrumentationRegistry
import com.android.server.wm.flicker.FlickerBuilderProvider
import com.android.server.wm.flicker.FlickerTestParameter
import com.android.server.wm.flicker.dsl.FlickerBuilder
import com.android.server.wm.flicker.endRotation
import com.android.server.wm.flicker.helpers.isRotated
import com.android.server.wm.flicker.helpers.setRotation
import com.android.server.wm.flicker.helpers.wakeUpAndGoToHomeScreen
@@ -179,15 +177,9 @@ abstract class AppPairsTransition(protected val testSpec: FlickerTestParameter)

    @Presubmit
    @Test
    open fun navBarLayerRotatesAndScales() {
        testSpec.navBarLayerRotatesAndScales(Surface.ROTATION_0,
            testSpec.config.endRotation)
    }
    open fun navBarLayerRotatesAndScales() = testSpec.navBarLayerRotatesAndScales()

    @Presubmit
    @Test
    open fun statusBarLayerRotatesScales() {
        testSpec.statusBarLayerRotatesScales(Surface.ROTATION_0,
            testSpec.config.endRotation)
    }
    open fun statusBarLayerRotatesScales() = testSpec.statusBarLayerRotatesScales()
}
 No newline at end of file
+118 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 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.flicker.bubble

import android.app.INotificationManager
import android.app.Instrumentation
import android.app.NotificationManager
import android.content.Context
import android.os.ServiceManager
import android.view.Surface
import androidx.test.filters.FlakyTest
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.By
import androidx.test.uiautomator.UiObject2
import androidx.test.uiautomator.Until
import com.android.server.wm.flicker.FlickerBuilderProvider
import com.android.server.wm.flicker.FlickerTestParameter
import com.android.server.wm.flicker.FlickerTestParameterFactory
import com.android.server.wm.flicker.dsl.FlickerBuilder
import com.android.server.wm.flicker.helpers.SYSTEMUI_PACKAGE
import com.android.server.wm.flicker.repetitions
import com.android.wm.shell.flicker.helpers.LaunchBubbleHelper
import org.junit.Test
import org.junit.runners.Parameterized

/**
 * Base configurations for Bubble flicker tests
 */
abstract class BaseBubbleScreen(protected val testSpec: FlickerTestParameter) {

    protected val instrumentation: Instrumentation = InstrumentationRegistry.getInstrumentation()
    protected val context: Context = instrumentation.context
    protected val testApp = LaunchBubbleHelper(instrumentation)

    protected val notifyManager = INotificationManager.Stub.asInterface(
            ServiceManager.getService(Context.NOTIFICATION_SERVICE))

    protected val packageManager = context.getPackageManager()
    protected val uid = packageManager.getApplicationInfo(
            testApp.component.packageName, 0).uid

    protected lateinit var addBubbleBtn: UiObject2
    protected lateinit var cancelAllBtn: UiObject2

    protected abstract val transition: FlickerBuilder.(Map<String, Any?>) -> Unit

    @JvmOverloads
    protected open fun buildTransition(
        extraSpec: FlickerBuilder.(Map<String, Any?>) -> Unit = {}
    ): FlickerBuilder.(Map<String, Any?>) -> Unit {
        return { configuration ->

            setup {
                test {
                    notifyManager.setBubblesAllowed(testApp.component.packageName,
                            uid, NotificationManager.BUBBLE_PREFERENCE_ALL)
                    testApp.launchViaIntent(wmHelper)
                    addBubbleBtn = device.wait(Until.findObject(
                            By.text("Add Bubble")), FIND_OBJECT_TIMEOUT)
                    cancelAllBtn = device.wait(Until.findObject(
                            By.text("Cancel All Bubble")), FIND_OBJECT_TIMEOUT)
                }
            }

            teardown {
                notifyManager.setBubblesAllowed(testApp.component.packageName,
                        uid, NotificationManager.BUBBLE_PREFERENCE_NONE)
                testApp.exit()
            }

            extraSpec(this, configuration)
        }
    }

    @FlakyTest
    @Test
    fun testAppIsAlwaysVisible() {
        testSpec.assertLayers {
            this.isVisible(testApp.component)
        }
    }

    @FlickerBuilderProvider
    fun buildFlicker(): FlickerBuilder {
        return FlickerBuilder(instrumentation).apply {
            repeat { testSpec.config.repetitions }
            transition(this, testSpec.config)
        }
    }

    companion object {
        @Parameterized.Parameters(name = "{0}")
        @JvmStatic
        fun getParams(): List<FlickerTestParameter> {
            return FlickerTestParameterFactory.getInstance()
                    .getConfigNonRotationTests(supportedRotations = listOf(Surface.ROTATION_0),
                            repetitions = 5)
        }

        const val FIND_OBJECT_TIMEOUT = 2000L
        const val SYSTEM_UI_PACKAGE = SYSTEMUI_PACKAGE
        const val BUBBLE_RES_NAME = "bubble_view"
    }
}
+65 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 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.flicker.bubble

import android.content.Context
import android.graphics.Point
import android.util.DisplayMetrics
import android.view.WindowManager
import androidx.test.filters.RequiresDevice
import androidx.test.uiautomator.By
import androidx.test.uiautomator.Until
import com.android.server.wm.flicker.FlickerParametersRunnerFactory
import com.android.server.wm.flicker.FlickerTestParameter
import com.android.server.wm.flicker.annotation.Group4
import com.android.server.wm.flicker.dsl.FlickerBuilder
import org.junit.runner.RunWith
import org.junit.runners.Parameterized

/**
 * Test launching a new activity from bubble.
 *
 * To run this test: `atest WMShellFlickerTests:DismissBubbleScreen`
 *
 * Actions:
 *     Dismiss a bubble notification
 */
@RequiresDevice
@RunWith(Parameterized::class)
@Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class)
@Group4
class DismissBubbleScreen(testSpec: FlickerTestParameter) : BaseBubbleScreen(testSpec) {

    val wm = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
    val displaySize = DisplayMetrics()

    override val transition: FlickerBuilder.(Map<String, Any?>) -> Unit
        get() = buildTransition() {
            setup {
                eachRun {
                    addBubbleBtn?.run { addBubbleBtn.click() } ?: error("Add Bubble not found")
                }
            }
            transitions {
                wm?.run { wm.getDefaultDisplay().getMetrics(displaySize) } ?: error("WM not found")
                val dist = Point((displaySize.widthPixels / 2), displaySize.heightPixels)
                val showBubble = device.wait(Until.findObject(
                        By.res(SYSTEM_UI_PACKAGE, BUBBLE_RES_NAME)), FIND_OBJECT_TIMEOUT)
                showBubble?.run { drag(dist, 1000) } ?: error("Show bubble not found")
            }
        }
}
+59 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 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.flicker.bubble

import androidx.test.filters.RequiresDevice
import androidx.test.uiautomator.By
import androidx.test.uiautomator.Until
import com.android.server.wm.flicker.FlickerParametersRunnerFactory
import com.android.server.wm.flicker.FlickerTestParameter
import com.android.server.wm.flicker.annotation.Group4
import com.android.server.wm.flicker.dsl.FlickerBuilder
import org.junit.runner.RunWith
import org.junit.runners.Parameterized

/**
 * Test launching a new activity from bubble.
 *
 * To run this test: `atest WMShellFlickerTests:ExpandBubbleScreen`
 *
 * Actions:
 *     Launch an app and enable app's bubble notification
 *     Send a bubble notification
 *     The activity for the bubble is launched
 */
@RequiresDevice
@RunWith(Parameterized::class)
@Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class)
@Group4
class ExpandBubbleScreen(testSpec: FlickerTestParameter) : BaseBubbleScreen(testSpec) {

    override val transition: FlickerBuilder.(Map<String, Any?>) -> Unit
        get() = buildTransition() {
            setup {
                test {
                    addBubbleBtn?.run { addBubbleBtn.click() } ?: error("Bubble widget not found")
                }
            }
            transitions {
                val showBubble = device.wait(Until.findObject(
                        By.res("com.android.systemui", "bubble_view")), FIND_OBJECT_TIMEOUT)
                showBubble?.run { showBubble.click() } ?: error("Bubble notify not found")
                device.pressBack()
            }
        }
}
Loading