@@ -8,6 +8,7 @@ import 'dart:io';
8
8
import 'dart:math' as math;
9
9
10
10
import 'package:path/path.dart' as path;
11
+ import 'package:retry/retry.dart' ;
11
12
12
13
import 'utils.dart' ;
13
14
@@ -193,6 +194,20 @@ abstract class Device {
193
194
/// Stop a process.
194
195
Future <void > stop (String packageName);
195
196
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
+
196
211
@override
197
212
String toString () {
198
213
return 'device: $deviceId ' ;
@@ -848,6 +863,23 @@ class AndroidDevice extends Device {
848
863
Future <void > reboot () {
849
864
return adb (< String > ['reboot' ]);
850
865
}
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
+ }
851
883
}
852
884
853
885
class IosDeviceDiscovery implements DeviceDiscovery {
@@ -1081,6 +1113,9 @@ class IosDevice extends Device {
1081
1113
Future <void > reboot () {
1082
1114
return Process .run ('idevicediagnostics' , < String > ['restart' , '-u' , deviceId]);
1083
1115
}
1116
+
1117
+ @override
1118
+ Future <void > awaitDevice () async {}
1084
1119
}
1085
1120
1086
1121
class LinuxDevice extends Device {
@@ -1133,6 +1168,9 @@ class LinuxDevice extends Device {
1133
1168
1134
1169
@override
1135
1170
Future <void > wakeUp () async { }
1171
+
1172
+ @override
1173
+ Future <void > awaitDevice () async {}
1136
1174
}
1137
1175
1138
1176
class MacosDevice extends Device {
@@ -1185,6 +1223,9 @@ class MacosDevice extends Device {
1185
1223
1186
1224
@override
1187
1225
Future <void > wakeUp () async { }
1226
+
1227
+ @override
1228
+ Future <void > awaitDevice () async {}
1188
1229
}
1189
1230
1190
1231
class WindowsDevice extends Device {
@@ -1237,6 +1278,9 @@ class WindowsDevice extends Device {
1237
1278
1238
1279
@override
1239
1280
Future <void > wakeUp () async { }
1281
+
1282
+ @override
1283
+ Future <void > awaitDevice () async {}
1240
1284
}
1241
1285
1242
1286
/// Fuchsia device.
@@ -1291,6 +1335,9 @@ class FuchsiaDevice extends Device {
1291
1335
Future <void > reboot () async {
1292
1336
// Unsupported.
1293
1337
}
1338
+
1339
+ @override
1340
+ Future <void > awaitDevice () async {}
1294
1341
}
1295
1342
1296
1343
/// Path to the `adb` executable.
@@ -1366,6 +1413,9 @@ class FakeDevice extends Device {
1366
1413
Future <void > reboot () async {
1367
1414
// Unsupported.
1368
1415
}
1416
+
1417
+ @override
1418
+ Future <void > awaitDevice () async {}
1369
1419
}
1370
1420
1371
1421
class FakeDeviceDiscovery implements DeviceDiscovery {
@@ -1428,6 +1478,5 @@ class FakeDeviceDiscovery implements DeviceDiscovery {
1428
1478
}
1429
1479
1430
1480
@override
1431
- Future <void > performPreflightTasks () async {
1432
- }
1481
+ Future <void > performPreflightTasks () async { }
1433
1482
}
0 commit comments