1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.platform.systemui_tapl.ui 18 19 import android.platform.systemui_tapl.ui.NotificationShadeType.NORMAL 20 import android.platform.systemui_tapl.ui.NotificationShadeType.SPLIT 21 import android.platform.systemui_tapl.utils.DeviceUtils.sysuiResSelector 22 import android.platform.uiautomatorhelpers.DeviceHelpers.assertVisible 23 import android.platform.uiautomatorhelpers.DeviceHelpers.uiDevice 24 import android.platform.uiautomatorhelpers.DeviceHelpers.waitForObj 25 import androidx.test.uiautomator.BySelector 26 import androidx.test.uiautomator.UiObject2 27 import com.google.common.collect.Range 28 import com.google.common.truth.Truth.assertWithMessage 29 30 /** 31 * Represents the universal media object(UMO) displayed in the [NotificationShade]. UMO is not the 32 * same as a media player. It contains a scrollable view called the Carousel, which can contain 33 * multiple media players and recent media cards. 34 */ 35 class UniversalMediaObject internal constructor() { 36 37 init { <lambda>null38 MEDIA_CAROUSEL_SCROLLER.assertVisible { "Media carousel not visible" } 39 } 40 41 /** Verifies that the media player is covering the entire space. */ assertCoversEntireSpacenull42 fun assertCoversEntireSpace() { 43 val mediaPlayerWidth = mediaCarouselUiObject.visibleBounds.width() 44 val deviceWidth = uiDevice.displayWidth 45 46 when (NotificationShade().type!!) { 47 NORMAL -> 48 assertWithMessage("Media player in normal shade is not covering the entire space") 49 .that(mediaPlayerWidth) 50 .isGreaterThan(deviceWidth / 2) 51 SPLIT -> 52 // should fit slightly less than half of the screen (due to margins) 53 assertWithMessage("Media player in split shade is not covering enough space") 54 .that(mediaPlayerWidth) 55 .isIn(Range.open(deviceWidth / 4 + 1, deviceWidth / 2)) 56 } 57 } 58 59 private val mediaCarouselUiObject: UiObject2 60 get() = uiDevice.waitForObj(MEDIA_CAROUSEL_SCROLLER) 61 62 companion object { 63 val MEDIA_CAROUSEL_SCROLLER: BySelector = sysuiResSelector("media_carousel_scroller") 64 } 65 66 /** Get the recommend media card on the UMO, or fail if it's not visible */ 67 val recentMediaCard: RecentMediaCard 68 get() = RecentMediaCard() 69 } 70