Skip to content

Commit 4e5e47e

Browse files
Add device ready check (#135526)
*Replace this paragraph with a description of what this PR is changing or adding, and why. Consider including before/after screenshots.* *List which issues are fixed by this PR. You must list at least one issue.* Fixes flutter/flutter#121420 *If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].*
1 parent d7739df commit 4e5e47e

File tree

2 files changed

+54
-13
lines changed

2 files changed

+54
-13
lines changed

dev/devicelab/lib/framework/devices.dart

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'dart:io';
88
import 'dart:math' as math;
99

1010
import 'package:path/path.dart' as path;
11+
import 'package:retry/retry.dart';
1112

1213
import 'utils.dart';
1314

@@ -193,6 +194,20 @@ abstract class Device {
193194
/// Stop a process.
194195
Future<void> stop(String packageName);
195196

197+
/// Wait for the device to become ready.
198+
Future<void> awaitDevice();
199+
200+
Future<void> uninstallApp() async {
201+
await flutter('install', options: <String>[
202+
'--uninstall-only',
203+
'-d',
204+
deviceId]);
205+
206+
await Future<void>.delayed(const Duration(seconds: 2));
207+
208+
await awaitDevice();
209+
}
210+
196211
@override
197212
String toString() {
198213
return 'device: $deviceId';
@@ -848,6 +863,23 @@ class AndroidDevice extends Device {
848863
Future<void> reboot() {
849864
return adb(<String>['reboot']);
850865
}
866+
867+
@override
868+
Future<void> awaitDevice() async {
869+
print('Waiting for device.');
870+
final String waitOut = await adb(<String>['wait-for-device']);
871+
print(waitOut);
872+
const RetryOptions retryOptions = RetryOptions(delayFactor: Duration(seconds: 1), maxAttempts: 10, maxDelay: Duration(minutes: 1));
873+
await retryOptions.retry(() async {
874+
final String adbShellOut = await adb(<String>['shell', 'getprop sys.boot_completed']);
875+
if (adbShellOut != '1') {
876+
print('Device not ready.');
877+
print(adbShellOut);
878+
throw const DeviceException('Phone not ready.');
879+
}
880+
}, retryIf: (Exception e) => e is DeviceException);
881+
print('Done waiting for device.');
882+
}
851883
}
852884

853885
class IosDeviceDiscovery implements DeviceDiscovery {
@@ -1081,6 +1113,9 @@ class IosDevice extends Device {
10811113
Future<void> reboot() {
10821114
return Process.run('idevicediagnostics', <String>['restart', '-u', deviceId]);
10831115
}
1116+
1117+
@override
1118+
Future<void> awaitDevice() async {}
10841119
}
10851120

10861121
class LinuxDevice extends Device {
@@ -1133,6 +1168,9 @@ class LinuxDevice extends Device {
11331168

11341169
@override
11351170
Future<void> wakeUp() async { }
1171+
1172+
@override
1173+
Future<void> awaitDevice() async {}
11361174
}
11371175

11381176
class MacosDevice extends Device {
@@ -1185,6 +1223,9 @@ class MacosDevice extends Device {
11851223

11861224
@override
11871225
Future<void> wakeUp() async { }
1226+
1227+
@override
1228+
Future<void> awaitDevice() async {}
11881229
}
11891230

11901231
class WindowsDevice extends Device {
@@ -1237,6 +1278,9 @@ class WindowsDevice extends Device {
12371278

12381279
@override
12391280
Future<void> wakeUp() async { }
1281+
1282+
@override
1283+
Future<void> awaitDevice() async {}
12401284
}
12411285

12421286
/// Fuchsia device.
@@ -1291,6 +1335,9 @@ class FuchsiaDevice extends Device {
12911335
Future<void> reboot() async {
12921336
// Unsupported.
12931337
}
1338+
1339+
@override
1340+
Future<void> awaitDevice() async {}
12941341
}
12951342

12961343
/// Path to the `adb` executable.
@@ -1366,6 +1413,9 @@ class FakeDevice extends Device {
13661413
Future<void> reboot() async {
13671414
// Unsupported.
13681415
}
1416+
1417+
@override
1418+
Future<void> awaitDevice() async {}
13691419
}
13701420

13711421
class FakeDeviceDiscovery implements DeviceDiscovery {
@@ -1428,6 +1478,5 @@ class FakeDeviceDiscovery implements DeviceDiscovery {
14281478
}
14291479

14301480
@override
1431-
Future<void> performPreflightTasks() async {
1432-
}
1481+
Future<void> performPreflightTasks() async { }
14331482
}

dev/devicelab/lib/tasks/perf_tests.dart

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -958,11 +958,7 @@ class StartupTest {
958958
}
959959
}
960960

961-
await flutter('install', options: <String>[
962-
'--uninstall-only',
963-
'-d',
964-
device.deviceId,
965-
]);
961+
await device.uninstallApp();
966962
}
967963

968964
final Map<String, dynamic> averageResults = _average(results, iterations);
@@ -1084,11 +1080,7 @@ class DevtoolsStartupTest {
10841080
await process.exitCode;
10851081
}
10861082

1087-
await flutter('install', options: <String>[
1088-
'--uninstall-only',
1089-
'-d',
1090-
device.deviceId,
1091-
]);
1083+
await device.uninstallApp();
10921084

10931085
if (sawLine) {
10941086
return TaskResult.success(null, benchmarkScoreKeys: <String>[]);
@@ -1850,7 +1842,7 @@ class MemoryTest {
18501842
}
18511843

18521844
await adb.cancel();
1853-
await flutter('install', options: <String>['--uninstall-only', '-d', device!.deviceId]);
1845+
await device!.uninstallApp();
18541846

18551847
final ListStatistics startMemoryStatistics = ListStatistics(_startMemory);
18561848
final ListStatistics endMemoryStatistics = ListStatistics(_endMemory);

0 commit comments

Comments
 (0)