Skip to content

Commit adc05a2

Browse files
Paige McAuliffecopybara-androidxtest
authored andcommitted
Make device mode enum value private
PiperOrigin-RevId: 547323151
1 parent 7780872 commit adc05a2

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ internal open class BaseSingleFoldDeviceAction(
5252
@OptIn(androidx.window.core.ExperimentalWindowApi::class)
5353
override fun perform(context: ActionContext, deviceController: DeviceController) {
5454
if (isRobolectricTest()) {
55-
deviceController.setDeviceMode(deviceMode.mode)
55+
deviceController.setDeviceMode(deviceMode.getMode())
5656
return
5757
}
5858
val activity =
@@ -97,7 +97,7 @@ internal open class BaseSingleFoldDeviceAction(
9797
}
9898
}
9999

100-
deviceController.setDeviceMode(deviceMode.mode)
100+
deviceController.setDeviceMode(deviceMode.getMode())
101101
latch.await(5, TimeUnit.SECONDS)
102102

103103
if (latch.getCount() != 0L) {

espresso/device/java/androidx/test/espresso/device/controller/DeviceMode.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

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

19+
import androidx.annotation.RestrictTo
20+
import androidx.annotation.RestrictTo.Scope
1921
import androidx.test.annotation.ExperimentalTestApi
2022

2123
/**
@@ -25,13 +27,20 @@ import androidx.test.annotation.ExperimentalTestApi
2527
* https://developer.android.com/guide/topics/large-screens/learn-about-foldables
2628
*/
2729
@ExperimentalTestApi
28-
enum class DeviceMode(val mode: Int) {
30+
enum class DeviceMode(private val mode: Int) {
2931
// the device screen is completely flat, like a tablet
3032
FLAT(0),
3133
// the device is folded with the hinge in a horizontal position
3234
TABLETOP(1),
3335
// the device is folded with the hinge in a vertical position
3436
BOOK(2),
3537
// the device screen is closed
36-
CLOSED(3)
38+
CLOSED(3);
39+
40+
/**
41+
* Returns the mode.
42+
*
43+
* @hide
44+
*/
45+
@RestrictTo(Scope.LIBRARY) fun getMode(): Int = mode
3746
}

espresso/device/java/androidx/test/espresso/device/controller/emulator/EmulatorController.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,20 @@ constructor(
4848

4949
override fun setDeviceMode(deviceMode: Int) {
5050
if (
51-
!(deviceMode == DeviceMode.FLAT.mode ||
52-
deviceMode == DeviceMode.TABLETOP.mode ||
53-
deviceMode == DeviceMode.BOOK.mode ||
54-
deviceMode == DeviceMode.CLOSED.mode)
51+
!(deviceMode == DeviceMode.FLAT.getMode() ||
52+
deviceMode == DeviceMode.TABLETOP.getMode() ||
53+
deviceMode == DeviceMode.BOOK.getMode() ||
54+
deviceMode == DeviceMode.CLOSED.getMode())
5555
) {
5656
throw UnsupportedDeviceOperationException(
5757
"The provided device mode is not supported on this device."
5858
)
5959
}
6060

6161
val postureValue: PostureValue =
62-
if (deviceMode == DeviceMode.FLAT.mode) {
62+
if (deviceMode == DeviceMode.FLAT.getMode()) {
6363
PostureValue.POSTURE_OPENED
64-
} else if (deviceMode == DeviceMode.CLOSED.mode) {
64+
} else if (deviceMode == DeviceMode.CLOSED.getMode()) {
6565
PostureValue.POSTURE_CLOSED
6666
} else {
6767
PostureValue.POSTURE_HALF_OPENED

0 commit comments

Comments
 (0)