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 https://github.com/flutter/flutter/issues/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].*
This commit is contained in:
parent
d7739dff68
commit
4e5e47e76a
@ -8,6 +8,7 @@ import 'dart:io';
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:retry/retry.dart';
|
||||
|
||||
import 'utils.dart';
|
||||
|
||||
@ -193,6 +194,20 @@ abstract class Device {
|
||||
/// Stop a process.
|
||||
Future<void> stop(String packageName);
|
||||
|
||||
/// Wait for the device to become ready.
|
||||
Future<void> awaitDevice();
|
||||
|
||||
Future<void> uninstallApp() async {
|
||||
await flutter('install', options: <String>[
|
||||
'--uninstall-only',
|
||||
'-d',
|
||||
deviceId]);
|
||||
|
||||
await Future<void>.delayed(const Duration(seconds: 2));
|
||||
|
||||
await awaitDevice();
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'device: $deviceId';
|
||||
@ -848,6 +863,23 @@ class AndroidDevice extends Device {
|
||||
Future<void> reboot() {
|
||||
return adb(<String>['reboot']);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> awaitDevice() async {
|
||||
print('Waiting for device.');
|
||||
final String waitOut = await adb(<String>['wait-for-device']);
|
||||
print(waitOut);
|
||||
const RetryOptions retryOptions = RetryOptions(delayFactor: Duration(seconds: 1), maxAttempts: 10, maxDelay: Duration(minutes: 1));
|
||||
await retryOptions.retry(() async {
|
||||
final String adbShellOut = await adb(<String>['shell', 'getprop sys.boot_completed']);
|
||||
if (adbShellOut != '1') {
|
||||
print('Device not ready.');
|
||||
print(adbShellOut);
|
||||
throw const DeviceException('Phone not ready.');
|
||||
}
|
||||
}, retryIf: (Exception e) => e is DeviceException);
|
||||
print('Done waiting for device.');
|
||||
}
|
||||
}
|
||||
|
||||
class IosDeviceDiscovery implements DeviceDiscovery {
|
||||
@ -1081,6 +1113,9 @@ class IosDevice extends Device {
|
||||
Future<void> reboot() {
|
||||
return Process.run('idevicediagnostics', <String>['restart', '-u', deviceId]);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> awaitDevice() async {}
|
||||
}
|
||||
|
||||
class LinuxDevice extends Device {
|
||||
@ -1133,6 +1168,9 @@ class LinuxDevice extends Device {
|
||||
|
||||
@override
|
||||
Future<void> wakeUp() async { }
|
||||
|
||||
@override
|
||||
Future<void> awaitDevice() async {}
|
||||
}
|
||||
|
||||
class MacosDevice extends Device {
|
||||
@ -1185,6 +1223,9 @@ class MacosDevice extends Device {
|
||||
|
||||
@override
|
||||
Future<void> wakeUp() async { }
|
||||
|
||||
@override
|
||||
Future<void> awaitDevice() async {}
|
||||
}
|
||||
|
||||
class WindowsDevice extends Device {
|
||||
@ -1237,6 +1278,9 @@ class WindowsDevice extends Device {
|
||||
|
||||
@override
|
||||
Future<void> wakeUp() async { }
|
||||
|
||||
@override
|
||||
Future<void> awaitDevice() async {}
|
||||
}
|
||||
|
||||
/// Fuchsia device.
|
||||
@ -1291,6 +1335,9 @@ class FuchsiaDevice extends Device {
|
||||
Future<void> reboot() async {
|
||||
// Unsupported.
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> awaitDevice() async {}
|
||||
}
|
||||
|
||||
/// Path to the `adb` executable.
|
||||
@ -1366,6 +1413,9 @@ class FakeDevice extends Device {
|
||||
Future<void> reboot() async {
|
||||
// Unsupported.
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> awaitDevice() async {}
|
||||
}
|
||||
|
||||
class FakeDeviceDiscovery implements DeviceDiscovery {
|
||||
@ -1428,6 +1478,5 @@ class FakeDeviceDiscovery implements DeviceDiscovery {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> performPreflightTasks() async {
|
||||
}
|
||||
Future<void> performPreflightTasks() async { }
|
||||
}
|
||||
|
@ -958,11 +958,7 @@ class StartupTest {
|
||||
}
|
||||
}
|
||||
|
||||
await flutter('install', options: <String>[
|
||||
'--uninstall-only',
|
||||
'-d',
|
||||
device.deviceId,
|
||||
]);
|
||||
await device.uninstallApp();
|
||||
}
|
||||
|
||||
final Map<String, dynamic> averageResults = _average(results, iterations);
|
||||
@ -1084,11 +1080,7 @@ class DevtoolsStartupTest {
|
||||
await process.exitCode;
|
||||
}
|
||||
|
||||
await flutter('install', options: <String>[
|
||||
'--uninstall-only',
|
||||
'-d',
|
||||
device.deviceId,
|
||||
]);
|
||||
await device.uninstallApp();
|
||||
|
||||
if (sawLine) {
|
||||
return TaskResult.success(null, benchmarkScoreKeys: <String>[]);
|
||||
@ -1850,7 +1842,7 @@ class MemoryTest {
|
||||
}
|
||||
|
||||
await adb.cancel();
|
||||
await flutter('install', options: <String>['--uninstall-only', '-d', device!.deviceId]);
|
||||
await device!.uninstallApp();
|
||||
|
||||
final ListStatistics startMemoryStatistics = ListStatistics(_startMemory);
|
||||
final ListStatistics endMemoryStatistics = ListStatistics(_endMemory);
|
||||
|
Loading…
x
Reference in New Issue
Block a user