diff --git a/packages/flutter_tools/lib/src/android/android_device.dart b/packages/flutter_tools/lib/src/android/android_device.dart index 5dc0627a60..6478c58d04 100644 --- a/packages/flutter_tools/lib/src/android/android_device.dart +++ b/packages/flutter_tools/lib/src/android/android_device.dart @@ -6,20 +6,15 @@ import 'dart:async'; import 'dart:convert'; import 'dart:io'; -import 'package:path/path.dart' as path; - import '../android/android_sdk.dart'; import '../application_package.dart'; import '../base/os.dart'; import '../base/logger.dart'; import '../base/process.dart'; import '../build_info.dart'; -import '../dart/package_map.dart'; import '../device.dart'; import '../flx.dart' as flx; import '../globals.dart'; -import '../toolchain.dart'; -import '../vmservice.dart'; import '../protocol_discovery.dart'; import 'adb.dart'; import 'android.dart'; @@ -30,8 +25,6 @@ const String _defaultAdbPath = 'adb'; // Path where the FLX bundle will be copied on the device. const String _deviceBundlePath = '/data/local/tmp/dev.flx'; -// Path where the snapshot will be copied on the device. -const String _deviceSnapshotPath = '/data/local/tmp/dev_snapshot.bin'; class AndroidDevices extends PollingDeviceDiscovery { AndroidDevices() : super('AndroidDevices'); @@ -434,74 +427,6 @@ class AndroidDevice extends Device { @override bool get supportsHotMode => true; - @override - Future runFromFile(ApplicationPackage package, - String scriptUri, - String packagesUri) async { - AndroidApk apk = package; - List cmd = adbCommandForDevice([ - 'shell', 'am', 'start', - '-a', 'android.intent.action.RUN', - '-d', _deviceBundlePath, - '-f', '0x20000000', // FLAG_ACTIVITY_SINGLE_TOP - ]); - cmd.addAll(['--es', 'file', scriptUri]); - cmd.addAll(['--es', 'packages', packagesUri]); - cmd.add(apk.launchActivity); - String result = runCheckedSync(cmd); - if (result.contains('Error: ')) { - printError(result.trim()); - return false; - } - return true; - } - - @override - bool get supportsRestart => true; - - @override - Future restartApp( - ApplicationPackage package, - LaunchResult result, { - String mainPath, - VMService observatory, - bool prebuiltApplication: false - }) async { - Directory tempDir = await Directory.systemTemp.createTemp('flutter_tools'); - - if (prebuiltApplication) { - return false; - } - - try { - String snapshotPath = path.join(tempDir.path, 'snapshot_blob.bin'); - int result = await flx.createSnapshot( - snapshotterPath: tools.getHostToolPath(HostTool.SkySnapshot), - mainPath: mainPath, - snapshotPath: snapshotPath, - packages: path.absolute(PackageMap.globalPackagesPath), - ); - - if (result != 0) { - printError('Failed to run the Flutter compiler; exit code: $result'); - return false; - } - - AndroidApk apk = package; - String androidActivity = apk.launchActivity; - bool success = await refreshSnapshot(androidActivity, snapshotPath); - - if (!success) { - printError('Error refreshing snapshot on $this.'); - return false; - } - - return true; - } finally { - tempDir.deleteSync(recursive: true); - } - } - @override Future stopApp(ApplicationPackage app) { List command = adbCommandForDevice(['shell', 'am', 'force-stop', app.id]); @@ -544,44 +469,6 @@ class AndroidDevice extends Device { @override bool isSupported() => true; - Future refreshSnapshot(String activity, String snapshotPath) async { - if (!FileSystemEntity.isFileSync(snapshotPath)) { - printError('Cannot find $snapshotPath'); - return false; - } - - RunResult result = await runAsync( - adbCommandForDevice(['push', snapshotPath, _deviceSnapshotPath]) - ); - if (result.exitCode != 0) { - printStatus(result.toString()); - return false; - } - - List cmd = adbCommandForDevice([ - 'shell', 'am', 'start', - '-a', 'android.intent.action.RUN', - '-d', _deviceBundlePath, - '-f', '0x20000000', // FLAG_ACTIVITY_SINGLE_TOP - '--es', 'snapshot', _deviceSnapshotPath, - activity, - ]); - result = await runAsync(cmd); - if (result.exitCode != 0) { - printStatus(result.toString()); - return false; - } - - final RegExp errorRegExp = new RegExp(r'^Error: .*$', multiLine: true); - Match errorMatch = errorRegExp.firstMatch(result.processResult.stdout); - if (errorMatch != null) { - printError(errorMatch.group(0)); - return false; - } - - return true; - } - @override bool get supportsScreenshot => true; diff --git a/packages/flutter_tools/lib/src/commands/daemon.dart b/packages/flutter_tools/lib/src/commands/daemon.dart index ae11b5235a..3c5e66d839 100644 --- a/packages/flutter_tools/lib/src/commands/daemon.dart +++ b/packages/flutter_tools/lib/src/commands/daemon.dart @@ -386,7 +386,7 @@ class AppDomain extends Domain { } bool isRestartSupported(bool enableHotReload, Device device) => - enableHotReload ? device.supportsHotMode : device.supportsRestart; + enableHotReload && device.supportsHotMode; Future restart(Map args) async { String appId = _getStringArg(args, 'appId', required: true); diff --git a/packages/flutter_tools/lib/src/device.dart b/packages/flutter_tools/lib/src/device.dart index df9bcc3d36..952e05d421 100644 --- a/packages/flutter_tools/lib/src/device.dart +++ b/packages/flutter_tools/lib/src/device.dart @@ -13,7 +13,6 @@ import 'base/os.dart'; import 'base/utils.dart'; import 'build_info.dart'; import 'globals.dart'; -import 'vmservice.dart'; import 'ios/devices.dart'; import 'ios/simulators.dart'; @@ -189,30 +188,7 @@ abstract class Device { }); /// Does this device implement support for hot reloading / restarting? - bool get supportsHotMode => false; - - /// Run from a file. Necessary for hot mode. - Future runFromFile(ApplicationPackage package, - String scriptUri, - String packagesUri) { - throw 'runFromFile unsupported'; - } - - bool get supportsRestart => false; - - bool get restartSendsFrameworkInitEvent => true; - - /// Restart the given app; the application will already have been launched with - /// [startApp]. - Future restartApp( - ApplicationPackage package, - LaunchResult result, { - String mainPath, - VMService observatory, - bool prebuiltApplication: false - }) async { - throw 'unsupported'; - } + bool get supportsHotMode => true; /// Stop an app package on the current device. Future stopApp(ApplicationPackage app); diff --git a/packages/flutter_tools/lib/src/hot.dart b/packages/flutter_tools/lib/src/hot.dart index cd18563075..262eccf13d 100644 --- a/packages/flutter_tools/lib/src/hot.dart +++ b/packages/flutter_tools/lib/src/hot.dart @@ -443,6 +443,9 @@ class HotRunner extends ResidentRunner { return true; } + @override + bool get supportsRestart => true; + @override Future restart({ bool fullRestart: false, bool pauseAfterRestart: false }) async { if (fullRestart) { @@ -555,7 +558,7 @@ class HotRunner extends ResidentRunner { printStatus('The Observatory debugger and profiler is available at: http://127.0.0.1:$_observatoryPort/'); if (details) { printStatus('To dump the widget hierarchy of the app (debugDumpApp), press "w".'); - printStatus('To dump the rendering tree of the app (debugDumpRenderTree), press "r".'); + printStatus('To dump the rendering tree of the app (debugDumpRenderTree), press "t".'); printStatus('To repeat this help message, press "h" or F1. To quit, press "q", F10, or Ctrl-C.'); } else { printStatus('For a more detailed help message, press "h" or F1. To quit, press "q", F10, or Ctrl-C.'); diff --git a/packages/flutter_tools/lib/src/ios/devices.dart b/packages/flutter_tools/lib/src/ios/devices.dart index 2fcdb31240..972c186325 100644 --- a/packages/flutter_tools/lib/src/ios/devices.dart +++ b/packages/flutter_tools/lib/src/ios/devices.dart @@ -12,7 +12,6 @@ import '../base/process.dart'; import '../build_info.dart'; import '../device.dart'; import '../globals.dart'; -import '../vmservice.dart'; import '../protocol_discovery.dart'; import 'mac.dart'; @@ -330,17 +329,6 @@ class IOSDevice extends Device { return localPort; } - @override - Future restartApp( - ApplicationPackage package, - LaunchResult result, { - String mainPath, - VMService observatory, - bool prebuiltApplication: false - }) async { - throw 'unsupported'; - } - @override Future stopApp(ApplicationPackage app) async { // Currently we don't have a way to stop an app running on iOS. diff --git a/packages/flutter_tools/lib/src/resident_runner.dart b/packages/flutter_tools/lib/src/resident_runner.dart index f42b12403f..51dec37a2f 100644 --- a/packages/flutter_tools/lib/src/resident_runner.dart +++ b/packages/flutter_tools/lib/src/resident_runner.dart @@ -45,7 +45,11 @@ abstract class ResidentRunner { bool shouldBuild: true }); - Future restart({ bool fullRestart: false, bool pauseAfterRestart: false }); + bool get supportsRestart => false; + + Future restart({ bool fullRestart: false, bool pauseAfterRestart: false }) { + throw 'unsupported'; + } Future stop() async { await stopEchoingDeviceLog(); @@ -80,6 +84,8 @@ abstract class ResidentRunner { }); if (!supportsServiceProtocol) return; + if (!supportsRestart) + return; ProcessSignal.SIGUSR1.watch().listen((ProcessSignal signal) async { printStatus('Caught SIGUSR1'); await restart(fullRestart: false); diff --git a/packages/flutter_tools/lib/src/run.dart b/packages/flutter_tools/lib/src/run.dart index 9b3ab803f7..11a20dbdaf 100644 --- a/packages/flutter_tools/lib/src/run.dart +++ b/packages/flutter_tools/lib/src/run.dart @@ -9,7 +9,6 @@ import 'package:meta/meta.dart'; import 'package:stack_trace/stack_trace.dart'; import 'application_package.dart'; -import 'base/logger.dart'; import 'base/utils.dart'; import 'commands/build_apk.dart'; import 'commands/install.dart'; @@ -17,7 +16,6 @@ import 'commands/trace.dart'; import 'device.dart'; import 'globals.dart'; import 'resident_runner.dart'; -import 'vmservice.dart'; class RunAndStayResident extends ResidentRunner { RunAndStayResident( @@ -62,40 +60,6 @@ class RunAndStayResident extends ResidentRunner { }); } - @override - Future restart({ bool fullRestart: false, bool pauseAfterRestart: false }) async { - if (vmService == null) { - printError('Debugging is not enabled.'); - return new OperationResult(1, 'debugging not enabled'); - } else { - Status status = logger.startProgress('Re-starting application...'); - - Future extensionAddedEvent; - - if (device.restartSendsFrameworkInitEvent) { - extensionAddedEvent = vmService.onExtensionEvent - .where((ServiceEvent event) => event.extensionKind == 'Flutter.FrameworkInitialization') - .first; - } - - bool result = await device.restartApp( - _package, - _result, - mainPath: _mainPath, - observatory: vmService, - prebuiltApplication: prebuiltMode - ); - - status.stop(); - - if (result && extensionAddedEvent != null) { - await extensionAddedEvent; - } - - return result ? OperationResult.ok : new OperationResult(1, 'restart error'); - } - } - Future _run({ bool traceStartup: false, Completer connectionInfoCompleter, @@ -219,17 +183,7 @@ class RunAndStayResident extends ResidentRunner { } @override - Future handleTerminalCommand(String code) async { - String lower = code.toLowerCase(); - if (lower == 'r' || code == AnsiTerminal.KEY_F5) { - if (!supportsServiceProtocol) - return; - if (device.supportsRestart) { - // F5, restart - await restart(); - } - } - } + Future handleTerminalCommand(String code) async => null; @override Future cleanupAfterSignal() async { @@ -245,15 +199,13 @@ class RunAndStayResident extends ResidentRunner { @override void printHelp({ @required bool details }) { bool haveDetails = false; - if (!prebuiltMode && device.supportsRestart && supportsServiceProtocol) - printStatus('To restart the app, press "r" or F5.'); if (_result.hasObservatory) printStatus('The Observatory debugger and profiler is available at: http://127.0.0.1:${_result.observatoryPort}/'); if (supportsServiceProtocol) { haveDetails = true; if (details) { printStatus('To dump the widget hierarchy of the app (debugDumpApp), press "w".'); - printStatus('To dump the rendering tree of the app (debugDumpRenderTree), press "r".'); + printStatus('To dump the rendering tree of the app (debugDumpRenderTree), press "t".'); } } if (haveDetails && !details) { @@ -270,4 +222,3 @@ class RunAndStayResident extends ResidentRunner { await device.stopApp(_package); } } -