Unverified Commit 4e5e47e7 authored by Ricardo Amador's avatar Ricardo Amador Committed by GitHub

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].*
parent d7739dff
...@@ -8,6 +8,7 @@ import 'dart:io'; ...@@ -8,6 +8,7 @@ import 'dart:io';
import 'dart:math' as math; import 'dart:math' as math;
import 'package:path/path.dart' as path; import 'package:path/path.dart' as path;
import 'package:retry/retry.dart';
import 'utils.dart'; import 'utils.dart';
...@@ -193,6 +194,20 @@ abstract class Device { ...@@ -193,6 +194,20 @@ abstract class Device {
/// Stop a process. /// Stop a process.
Future<void> stop(String packageName); 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 @override
String toString() { String toString() {
return 'device: $deviceId'; return 'device: $deviceId';
...@@ -848,6 +863,23 @@ class AndroidDevice extends Device { ...@@ -848,6 +863,23 @@ class AndroidDevice extends Device {
Future<void> reboot() { Future<void> reboot() {
return adb(<String>['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 { class IosDeviceDiscovery implements DeviceDiscovery {
...@@ -1081,6 +1113,9 @@ class IosDevice extends Device { ...@@ -1081,6 +1113,9 @@ class IosDevice extends Device {
Future<void> reboot() { Future<void> reboot() {
return Process.run('idevicediagnostics', <String>['restart', '-u', deviceId]); return Process.run('idevicediagnostics', <String>['restart', '-u', deviceId]);
} }
@override
Future<void> awaitDevice() async {}
} }
class LinuxDevice extends Device { class LinuxDevice extends Device {
...@@ -1133,6 +1168,9 @@ class LinuxDevice extends Device { ...@@ -1133,6 +1168,9 @@ class LinuxDevice extends Device {
@override @override
Future<void> wakeUp() async { } Future<void> wakeUp() async { }
@override
Future<void> awaitDevice() async {}
} }
class MacosDevice extends Device { class MacosDevice extends Device {
...@@ -1185,6 +1223,9 @@ class MacosDevice extends Device { ...@@ -1185,6 +1223,9 @@ class MacosDevice extends Device {
@override @override
Future<void> wakeUp() async { } Future<void> wakeUp() async { }
@override
Future<void> awaitDevice() async {}
} }
class WindowsDevice extends Device { class WindowsDevice extends Device {
...@@ -1237,6 +1278,9 @@ class WindowsDevice extends Device { ...@@ -1237,6 +1278,9 @@ class WindowsDevice extends Device {
@override @override
Future<void> wakeUp() async { } Future<void> wakeUp() async { }
@override
Future<void> awaitDevice() async {}
} }
/// Fuchsia device. /// Fuchsia device.
...@@ -1291,6 +1335,9 @@ class FuchsiaDevice extends Device { ...@@ -1291,6 +1335,9 @@ class FuchsiaDevice extends Device {
Future<void> reboot() async { Future<void> reboot() async {
// Unsupported. // Unsupported.
} }
@override
Future<void> awaitDevice() async {}
} }
/// Path to the `adb` executable. /// Path to the `adb` executable.
...@@ -1366,6 +1413,9 @@ class FakeDevice extends Device { ...@@ -1366,6 +1413,9 @@ class FakeDevice extends Device {
Future<void> reboot() async { Future<void> reboot() async {
// Unsupported. // Unsupported.
} }
@override
Future<void> awaitDevice() async {}
} }
class FakeDeviceDiscovery implements DeviceDiscovery { class FakeDeviceDiscovery implements DeviceDiscovery {
...@@ -1428,6 +1478,5 @@ class FakeDeviceDiscovery implements DeviceDiscovery { ...@@ -1428,6 +1478,5 @@ class FakeDeviceDiscovery implements DeviceDiscovery {
} }
@override @override
Future<void> performPreflightTasks() async { Future<void> performPreflightTasks() async { }
}
} }
...@@ -958,11 +958,7 @@ class StartupTest { ...@@ -958,11 +958,7 @@ class StartupTest {
} }
} }
await flutter('install', options: <String>[ await device.uninstallApp();
'--uninstall-only',
'-d',
device.deviceId,
]);
} }
final Map<String, dynamic> averageResults = _average(results, iterations); final Map<String, dynamic> averageResults = _average(results, iterations);
...@@ -1084,11 +1080,7 @@ class DevtoolsStartupTest { ...@@ -1084,11 +1080,7 @@ class DevtoolsStartupTest {
await process.exitCode; await process.exitCode;
} }
await flutter('install', options: <String>[ await device.uninstallApp();
'--uninstall-only',
'-d',
device.deviceId,
]);
if (sawLine) { if (sawLine) {
return TaskResult.success(null, benchmarkScoreKeys: <String>[]); return TaskResult.success(null, benchmarkScoreKeys: <String>[]);
...@@ -1850,7 +1842,7 @@ class MemoryTest { ...@@ -1850,7 +1842,7 @@ class MemoryTest {
} }
await adb.cancel(); await adb.cancel();
await flutter('install', options: <String>['--uninstall-only', '-d', device!.deviceId]); await device!.uninstallApp();
final ListStatistics startMemoryStatistics = ListStatistics(_startMemory); final ListStatistics startMemoryStatistics = ListStatistics(_startMemory);
final ListStatistics endMemoryStatistics = ListStatistics(_endMemory); final ListStatistics endMemoryStatistics = ListStatistics(_endMemory);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment