Skip to content

Commit 071a189

Browse files
committed
Merge branch 'main' into cherrypickscript
2 parents faa482c + 136bf7f commit 071a189

File tree

17 files changed

+185
-152
lines changed

17 files changed

+185
-152
lines changed

WORKSPACE

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ load(
6767
"GUAVA_VERSION",
6868
"JUNIT_VERSION",
6969
"UIAUTOMATOR_VERSION",
70+
"ATF_VERSION"
7071
)
7172

7273
# gRPC
@@ -104,6 +105,7 @@ maven_install(
104105
"androidx.viewpager:viewpager:" + ANDROIDX_VIEWPAGER_VERSION,
105106
"androidx.window:window:" + ANDROIDX_WINDOW_VERSION,
106107
"androidx.window:window-java:" + ANDROIDX_WINDOW_VERSION,
108+
"androidx.window:window-core:" + ANDROIDX_WINDOW_VERSION,
107109
"aopalliance:aopalliance:1.0",
108110
"com.android.tools.lint:lint-api:30.1.0",
109111
"com.android.tools.lint:lint-checks:30.1.0",
@@ -128,7 +130,7 @@ maven_install(
128130
),
129131
],
130132
group = "com.google.android.apps.common.testing.accessibility.framework",
131-
version = "3.1",
133+
version = ATF_VERSION,
132134
),
133135
"com.google.android.material:material:" + GOOGLE_MATERIAL_VERSION,
134136
"com.google.auto.value:auto-value:1.5.1",
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
"""Defines current released AXT versions."""
22

3-
RUNNER_VERSION = "1.6.0-alpha07"
4-
RULES_VERSION = "1.6.0-alpha04"
5-
MONITOR_VERSION = "1.7.0-alpha05"
6-
ESPRESSO_VERSION = "3.6.0-alpha04"
7-
CORE_VERSION = "1.6.0-alpha06"
8-
ESPRESSO_DEVICE_VERSION = "1.0.0-alpha09"
9-
ANDROIDX_JUNIT_VERSION = "1.2.0-alpha04"
10-
ANDROIDX_TRUTH_VERSION = "1.6.0-alpha04"
11-
ORCHESTRATOR_VERSION = "1.5.0-alpha04"
12-
SERVICES_VERSION = "1.5.0-alpha04"
3+
RUNNER_VERSION = "1.6.0"
4+
RULES_VERSION = "1.6.0"
5+
MONITOR_VERSION = "1.7.0"
6+
ESPRESSO_VERSION = "3.6.0"
7+
CORE_VERSION = "1.6.0"
8+
ESPRESSO_DEVICE_VERSION = "1.0.0"
9+
ANDROIDX_JUNIT_VERSION = "1.2.0"
10+
ANDROIDX_TRUTH_VERSION = "1.6.0"
11+
ORCHESTRATOR_VERSION = "1.5.0"
12+
SERVICES_VERSION = "1.5.0"

espresso/device/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
**Breaking Changes**
1515

1616
**API Changes**
17+
* Update WidthSizeClass and HeightSizeClass to use androidx.window size classes
1718

1819
**Breaking API Changes**
1920

espresso/device/java/androidx/test/espresso/device/action/DisplaySizeAction.kt

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import kotlin.math.roundToInt
3737
/** Action to set the test device to the provided display size. */
3838
internal class DisplaySizeAction(
3939
val widthDisplaySize: WidthSizeClass,
40-
val heightDisplaySize: HeightSizeClass
40+
val heightDisplaySize: HeightSizeClass,
4141
) : DeviceAction {
4242
override fun perform(deviceController: DeviceController) {
4343
if (getDeviceApiLevel() < 24) {
@@ -48,12 +48,11 @@ internal class DisplaySizeAction(
4848

4949
val currentActivity = getResumedActivityOrNull()
5050
if (currentActivity != null) {
51-
val displaySize = calculateCurrentDisplayWidthAndHeightDp(currentActivity)
52-
val startingWidth = displaySize.first
53-
val startingHeight = displaySize.second
51+
val (startingWidthDp, startingHeightDp) =
52+
calculateCurrentDisplayWidthAndHeightDp(currentActivity)
5453
if (
55-
widthDisplaySize == WidthSizeClass.compute(startingWidth) &&
56-
heightDisplaySize == HeightSizeClass.compute(startingHeight)
54+
WidthSizeClass.compute(startingWidthDp) == widthDisplaySize &&
55+
HeightSizeClass.compute(startingHeightDp) == heightDisplaySize
5756
) {
5857
Log.d(TAG, "Device display is already the requested size, no changes needed.")
5958
return
@@ -65,10 +64,10 @@ internal class DisplaySizeAction(
6564
object : View(currentActivity) {
6665
override fun onConfigurationChanged(newConfig: Configuration?) {
6766
super.onConfigurationChanged(newConfig)
68-
val currentDisplaySize = calculateCurrentDisplayWidthAndHeightDp(currentActivity)
67+
val (newWidthDp, newHeightDp) = calculateCurrentDisplayWidthAndHeightDp(currentActivity)
6968
if (
70-
WidthSizeClass.compute(currentDisplaySize.first) == widthDisplaySize &&
71-
HeightSizeClass.compute(currentDisplaySize.second) == heightDisplaySize
69+
WidthSizeClass.compute(newWidthDp) == widthDisplaySize &&
70+
HeightSizeClass.compute(newHeightDp) == heightDisplaySize
7271
) {
7372
latch.countDown()
7473
}
@@ -78,21 +77,21 @@ internal class DisplaySizeAction(
7877
currentActivity.getWindow().findViewById(android.R.id.content) as ViewGroup
7978
currentActivity.runOnUiThread { container.addView(currentActivityView) }
8079

81-
val widthDp = WidthSizeClass.getWidthDpInSizeClass(widthDisplaySize)
82-
val heightDp = HeightSizeClass.getHeightDpInSizeClass(heightDisplaySize)
80+
val widthDpToSet = WidthSizeClass.getWidthDpInSizeClass(widthDisplaySize)
81+
val heightDpToSet = HeightSizeClass.getHeightDpInSizeClass(heightDisplaySize)
8382

84-
executeShellCommand("wm size ${widthDp}dpx${heightDp}dp")
83+
executeShellCommand("wm size ${widthDpToSet}dpx${heightDpToSet}dp")
8584

8685
latch.await(5, TimeUnit.SECONDS)
8786
currentActivity.runOnUiThread { container.removeView(currentActivityView) }
8887

89-
val finalSize = calculateCurrentDisplayWidthAndHeightDp(currentActivity)
88+
val (finalWidthDp, finalHeightDp) = calculateCurrentDisplayWidthAndHeightDp(currentActivity)
9089
if (
91-
WidthSizeClass.compute(finalSize.first) != widthDisplaySize ||
92-
HeightSizeClass.compute(finalSize.second) != heightDisplaySize
90+
WidthSizeClass.compute(finalWidthDp) != widthDisplaySize ||
91+
HeightSizeClass.compute(finalHeightDp) != heightDisplaySize
9392
) {
9493
// Display could not be set to the requested size, reset to starting size
95-
executeShellCommand("wm size ${startingWidth}dpx${startingHeight}dp")
94+
executeShellCommand("wm size ${startingWidthDp}dpx${startingHeightDp}dp")
9695
throw UnsupportedDeviceOperationException(
9796
"Device could not be set to the requested display size."
9897
)

espresso/device/java/androidx/test/espresso/device/filter/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ kt_android_library(
2222
"//espresso/device/java/androidx/test/espresso/device/sizeclass",
2323
"//runner/android_junit_runner",
2424
"//runner/monitor",
25+
"@maven//:androidx_window_window_core",
2526
"@maven//:junit_junit",
2627
],
2728
)
@@ -37,6 +38,7 @@ kt_android_library(
3738
"//espresso/device/java/androidx/test/espresso/device/sizeclass",
3839
"//runner/android_junit_runner",
3940
"//runner/monitor",
41+
"@maven//:androidx_window_window_core",
4042
"@maven//:junit_junit",
4143
],
4244
)

espresso/device/java/androidx/test/espresso/device/filter/RequiresDisplayFilter.kt

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@
1616
package androidx.test.espresso.device.filter
1717

1818
import android.app.Instrumentation
19-
import androidx.test.espresso.device.sizeclass.HeightSizeClass
20-
import androidx.test.espresso.device.sizeclass.WidthSizeClass
19+
import androidx.test.espresso.device.sizeclass.HeightSizeClass.Companion.HeightSizeClassEnum
20+
import androidx.test.espresso.device.sizeclass.WidthSizeClass.Companion.WidthSizeClassEnum
2121
import androidx.test.filters.AbstractFilter
2222
import androidx.test.platform.app.InstrumentationRegistry
23+
import androidx.window.core.layout.WindowHeightSizeClass
24+
import androidx.window.core.layout.WindowSizeClass
25+
import androidx.window.core.layout.WindowWidthSizeClass
2326
import org.junit.runner.Description
2427

2528
/**
@@ -37,10 +40,9 @@ internal class RequiresDisplayFilter(
3740

3841
if (!annotations.isEmpty() && annotations[0] is RequiresDisplay) {
3942
val requiresDisplay: RequiresDisplay = annotations[0] as RequiresDisplay
40-
return requiresDisplay.widthSizeClass ==
41-
WidthSizeClass.getEnum(WidthSizeClass.compute(getWidthDp())) &&
42-
requiresDisplay.heightSizeClass ==
43-
HeightSizeClass.getEnum(HeightSizeClass.compute(getHeightDp()))
43+
val windowSize = WindowSizeClass.compute(getWidthDp(), getHeightDp())
44+
return requiresDisplay.widthSizeClass == getWidthEnum(windowSize.windowWidthSizeClass) &&
45+
requiresDisplay.heightSizeClass == getHeightEnum(windowSize.windowHeightSizeClass)
4446
} else {
4547
return true // no RequiresDisplay annotation, run the test
4648
}
@@ -51,14 +53,30 @@ internal class RequiresDisplayFilter(
5153
}
5254

5355
/** Returns the current screen width in dp */
54-
private fun getWidthDp(): Int {
56+
private fun getWidthDp(): Float {
5557
val displayMetrics = instrumentation.getTargetContext().getResources().displayMetrics
56-
return (displayMetrics.widthPixels / displayMetrics.density).toInt()
58+
return (displayMetrics.widthPixels / displayMetrics.density)
5759
}
5860

5961
/** Returns the current screen height in dp */
60-
private fun getHeightDp(): Int {
62+
private fun getHeightDp(): Float {
6163
val displayMetrics = instrumentation.getTargetContext().getResources().displayMetrics
62-
return (displayMetrics.heightPixels / displayMetrics.density).toInt()
64+
return (displayMetrics.heightPixels / displayMetrics.density)
65+
}
66+
67+
private fun getWidthEnum(widthSizeClass: WindowWidthSizeClass): WidthSizeClassEnum {
68+
return when (widthSizeClass) {
69+
WindowWidthSizeClass.COMPACT -> WidthSizeClassEnum.COMPACT
70+
WindowWidthSizeClass.MEDIUM -> WidthSizeClassEnum.MEDIUM
71+
else -> WidthSizeClassEnum.EXPANDED
72+
}
73+
}
74+
75+
private fun getHeightEnum(heightSizeClass: WindowHeightSizeClass): HeightSizeClassEnum {
76+
return when (heightSizeClass) {
77+
WindowHeightSizeClass.COMPACT -> HeightSizeClassEnum.COMPACT
78+
WindowHeightSizeClass.MEDIUM -> HeightSizeClassEnum.MEDIUM
79+
else -> HeightSizeClassEnum.EXPANDED
80+
}
6381
}
6482
}

espresso/device/java/androidx/test/espresso/device/sizeclass/BUILD

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Description:
22
# Size classes
3-
# TODO(b/236387720): Replace these classes with core window module size classes when available
43

54
load("//build_extensions:kt_android_library.bzl", "kt_android_library")
65

@@ -18,5 +17,7 @@ kt_android_library(
1817
testonly = 1,
1918
srcs = glob(["*.kt"]),
2019
deps = [
20+
"//runner/monitor",
21+
"@maven//:androidx_window_window_core",
2122
],
2223
)

espresso/device/java/androidx/test/espresso/device/sizeclass/HeightSizeClass.kt

Lines changed: 20 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,48 +16,27 @@
1616

1717
package androidx.test.espresso.device.sizeclass
1818

19+
import androidx.test.platform.app.InstrumentationRegistry
20+
import androidx.window.core.layout.WindowHeightSizeClass
21+
import androidx.window.core.layout.WindowSizeClass
22+
1923
/**
2024
* A class to create buckets for the height of a window.
2125
*
2226
* For details on window size classes, see
2327
* https://developer.android.com/guide/topics/large-screens/support-different-screen-sizes.
2428
*/
2529
public class HeightSizeClass
26-
private constructor(
27-
private val lowerBound: Int,
28-
internal val upperBound: Int,
29-
private val description: String
30-
) {
31-
override fun toString(): String {
32-
return description
33-
}
34-
35-
override fun equals(other: Any?): Boolean {
36-
if (this === other) return true
37-
if (javaClass != other?.javaClass) return false
38-
other as HeightSizeClass
39-
if (lowerBound != other.lowerBound) return false
40-
if (upperBound != other.upperBound) return false
41-
if (description != other.description) return false
42-
return true
43-
}
44-
45-
override fun hashCode(): Int {
46-
var result = lowerBound
47-
result = 31 * result + upperBound
48-
result = 31 * result + description.hashCode()
49-
return result
50-
}
51-
30+
private constructor(private val windowHeightSizeClass: WindowHeightSizeClass) {
5231
public companion object {
5332
/** A bucket to represent a compact height. One use-case is a phone that is in landscape. */
54-
@JvmField public val COMPACT: HeightSizeClass = HeightSizeClass(0, 480, "COMPACT")
33+
@JvmField public val COMPACT: HeightSizeClass = HeightSizeClass(WindowHeightSizeClass.COMPACT)
5534
/** A bucket to represent a medium height. One use-case is a phone in portrait or a tablet. */
56-
@JvmField public val MEDIUM: HeightSizeClass = HeightSizeClass(480, 900, "MEDIUM")
35+
@JvmField public val MEDIUM: HeightSizeClass = HeightSizeClass(WindowHeightSizeClass.MEDIUM)
5736
/**
5837
* A bucket to represent an expanded height window. One use-case is a tablet or a desktop app.
5938
*/
60-
@JvmField public val EXPANDED: HeightSizeClass = HeightSizeClass(900, Int.MAX_VALUE, "EXPANDED")
39+
@JvmField public val EXPANDED: HeightSizeClass = HeightSizeClass(WindowHeightSizeClass.EXPANDED)
6140

6241
/**
6342
* Returns a recommended [HeightSizeClass] for the height of a window given the height in DP.
@@ -68,12 +47,17 @@ private constructor(
6847
*/
6948
@JvmStatic
7049
public fun compute(dpHeight: Int): HeightSizeClass {
71-
return when {
72-
dpHeight < COMPACT.lowerBound -> {
73-
throw IllegalArgumentException("Negative size: $dpHeight")
74-
}
75-
dpHeight < COMPACT.upperBound -> COMPACT
76-
dpHeight < MEDIUM.upperBound -> MEDIUM
50+
if (dpHeight < 0) {
51+
throw IllegalArgumentException("Negative size: $dpHeight")
52+
}
53+
val instrumentation = InstrumentationRegistry.getInstrumentation()
54+
val displayMetrics = instrumentation.getTargetContext().getResources().displayMetrics
55+
val dpWidth = displayMetrics.widthPixels / displayMetrics.density
56+
val heightSizeClass =
57+
WindowSizeClass.compute(dpWidth, dpHeight.toFloat()).windowHeightSizeClass
58+
return when (heightSizeClass) {
59+
WindowHeightSizeClass.COMPACT -> COMPACT
60+
WindowHeightSizeClass.MEDIUM -> MEDIUM
7761
else -> EXPANDED
7862
}
7963
}
@@ -111,7 +95,7 @@ private constructor(
11195
public enum class HeightSizeClassEnum(val description: String) {
11296
COMPACT("COMPACT"),
11397
MEDIUM("MEDIUM"),
114-
EXPANDED("EXPANDED")
98+
EXPANDED("EXPANDED"),
11599
}
116100
}
117101
}

espresso/device/java/androidx/test/espresso/device/sizeclass/WidthSizeClass.kt

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,49 +16,29 @@
1616

1717
package androidx.test.espresso.device.sizeclass
1818

19+
import androidx.test.platform.app.InstrumentationRegistry
20+
import androidx.window.core.layout.WindowSizeClass
21+
import androidx.window.core.layout.WindowWidthSizeClass
22+
1923
/**
2024
* A class to create buckets for the width of a window.
2125
*
2226
* For details on window size classes, see
2327
* https://developer.android.com/guide/topics/large-screens/support-different-screen-sizes.
2428
*/
2529
public class WidthSizeClass
26-
private constructor(
27-
private val lowerBound: Int,
28-
internal val upperBound: Int,
29-
private val description: String
30-
) {
31-
override fun toString(): String {
32-
return description
33-
}
34-
35-
override fun equals(other: Any?): Boolean {
36-
if (this === other) return true
37-
if (javaClass != other?.javaClass) return false
38-
other as WidthSizeClass
39-
if (lowerBound != other.lowerBound) return false
40-
if (upperBound != other.upperBound) return false
41-
if (description != other.description) return false
42-
return true
43-
}
44-
45-
override fun hashCode(): Int {
46-
var result = lowerBound
47-
result = 31 * result + upperBound
48-
result = 31 * result + description.hashCode()
49-
return result
50-
}
30+
private constructor(private val windowWidthSizeClass: WindowWidthSizeClass) {
5131

5232
public companion object {
5333
/** A bucket to represent a compact width window. One use-case is a phone in portrait. */
54-
@JvmField public val COMPACT: WidthSizeClass = WidthSizeClass(0, 600, "COMPACT")
34+
@JvmField public val COMPACT: WidthSizeClass = WidthSizeClass(WindowWidthSizeClass.COMPACT)
5535
/**
5636
* A bucket to represent a medium width window. Some use-cases are a phone in landscape or a
5737
* tablet.
5838
*/
59-
@JvmField public val MEDIUM: WidthSizeClass = WidthSizeClass(600, 840, "MEDIUM")
39+
@JvmField public val MEDIUM: WidthSizeClass = WidthSizeClass(WindowWidthSizeClass.MEDIUM)
6040
/** A bucket to represent an expanded width window. One use-case is a desktop app. */
61-
@JvmField public val EXPANDED: WidthSizeClass = WidthSizeClass(840, Int.MAX_VALUE, "EXPANDED")
41+
@JvmField public val EXPANDED: WidthSizeClass = WidthSizeClass(WindowWidthSizeClass.EXPANDED)
6242

6343
/**
6444
* Returns a recommended [WidthSizeClass] for the width of a window given the width in DP.
@@ -69,12 +49,16 @@ private constructor(
6949
*/
7050
@JvmStatic
7151
public fun compute(dpWidth: Int): WidthSizeClass {
72-
return when {
73-
dpWidth < COMPACT.lowerBound -> {
74-
throw IllegalArgumentException("Negative size: $dpWidth")
75-
}
76-
dpWidth < COMPACT.upperBound -> COMPACT
77-
dpWidth < MEDIUM.upperBound -> MEDIUM
52+
if (dpWidth < 0) {
53+
throw IllegalArgumentException("Negative size: $dpWidth")
54+
}
55+
val instrumentation = InstrumentationRegistry.getInstrumentation()
56+
val displayMetrics = instrumentation.getTargetContext().getResources().displayMetrics
57+
val dpHeight = displayMetrics.heightPixels / displayMetrics.density
58+
val widthSizeClass = WindowSizeClass.compute(dpWidth.toFloat(), dpHeight).windowWidthSizeClass
59+
return when (widthSizeClass) {
60+
WindowWidthSizeClass.COMPACT -> COMPACT
61+
WindowWidthSizeClass.MEDIUM -> MEDIUM
7862
else -> EXPANDED
7963
}
8064
}

0 commit comments

Comments
 (0)