Skip to content

Commit 295d12f

Browse files
author
Paulina Strychacz
committed
new regex to get wifi name for Android 9 & 10 devices
1 parent c366cbd commit 295d12f

File tree

3 files changed

+171
-146
lines changed

3 files changed

+171
-146
lines changed

src/main/kotlin/internal/DeviceWrapper.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,16 @@ class DeviceWrapper(val device: IDevice, val outputReceiverProvider: OutputRecei
5252
}
5353

5454
fun checkWifi(wifi: String) {
55-
val output = analyzeOutputOfShellCommandByRegex(DUMPSYS_WIFI, "mNetworkInfo .+ extra: \"(.+)\"")
55+
val output: Matcher = try {
56+
analyzeOutputOfShellCommandByRegex(DUMPSYS_WIFI, "mNetworkInfo .+ extra: \"(.+)\"")
57+
}
58+
catch (e: GradleException) {
59+
// Android 9 & 10
60+
analyzeOutputOfShellCommandByRegex(DUMPSYS_WIFI, "mWifiInfo\\s+SSID:\\s+(.+?),")
61+
}
5662
val currentWifi = output.group(1)
5763
if (currentWifi != wifi) {
58-
throw GradleException("Device ${getDetails()} is not connected to wifi with name $wifi")
64+
throw GradleException("Device ${getDetails()} is not connected to WiFi named $wifi. Current WiFi is: $currentWifi")
5965
}
6066
}
6167

src/test/kotlin/unitTest/tasks/CheckWifiTaskUnitTest.kt

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,16 @@ class CheckWifiTaskUnitTest : BaseUnitTest() {
2929
val bridge: AndroidDebugBridge = mock()
3030
val outputReceiver: CollectingOutputReceiver = mock()
3131
val outputReceiverProvider: OutputReceiverProvider = mock()
32-
val defaultPluginTask: DefaultPluginTask = mock()
3332

3433
val deviceCommunicator = DeviceCommunicator(bridge, outputReceiverProvider)
35-
val noDevices = emptyArray<IDevice>()
36-
val wifi = "wifi"
34+
val wifi = "wlanName"
3735
val devices = arrayOf(device)
3836
val mNetworkInfo = "mNetworkInfo [type: WIFI[], extra: \"$wifi\"]"
37+
val wifiDumpsysAndroid9 = "mWifiInfo SSID: $wifi, BSSID: 50:06:04:c2:f5:5d, MAC: a8:db:03:e0:e1:e5, Supplicant state: COMPLETED, RSSI: -62, Link speed: 270Mbps, Frequency: 5180MHz, Net ID: 2, Metered hint: false, GigaAp: false, VenueName: null, WifiMode: 4, score: 60\n" +
38+
"mDhcpResults IP address 172.30.13.47/20 Gateway 172.30.15.245 DNS servers: [ 194.25.0.52 8.8.8.8 8.8.4.4 ] Domains asv.cor DHCP server /10.10.54.54 Vendor info null lease 1800 seconds\n" +
39+
"mNetworkInfo [type: WIFI[], state: CONNECTED/CONNECTED, reason: (unspecified), extra: (none), failover: false, available: true, roaming: false]\n"
40+
41+
3942

4043
lateinit var projectDir: File
4144
lateinit var project: Project
@@ -53,31 +56,39 @@ class CheckWifiTaskUnitTest : BaseUnitTest() {
5356
task.wifi = wifi
5457

5558
given(outputReceiverProvider.get()).willReturn(outputReceiver)
59+
given(bridge.devices).willReturn(devices)
60+
5661
}
5762

5863
@Test(expected = GradleException::class)
5964
fun `throw gradle exception when string in extension is empty`() {
6065
task.wifi = ""
61-
given(bridge.devices).willReturn(devices)
6266

6367
task.runTask1()
6468
}
6569

6670
@Test(expected = GradleException::class)
6771
fun `throw gradle exception when string in extension is blank`() {
6872
task.wifi = " "
69-
given(bridge.devices).willReturn(devices)
7073

7174
task.runTask1()
7275
}
7376

7477
@Test
7578
fun `no gradle exception is thrown when connected to right wifi`() {
76-
given(bridge.devices).willReturn(devices)
7779
given(outputReceiver.output).willReturn(mNetworkInfo)
7880

7981
task.runTask2(device)
8082

8183
thenDeviceShouldGetDetails(device)
8284
}
85+
86+
@Test
87+
fun `no gradle exception is thrown when connected to right wifi on Android 9 and 10`() {
88+
given(outputReceiver.output).willReturn(wifiDumpsysAndroid9)
89+
90+
task.runTask2(device)
91+
92+
thenDeviceShouldGetDetails(device)
93+
}
8394
}

0 commit comments

Comments
 (0)