Commit e9086552 authored by John McCutchan's avatar John McCutchan Committed by GitHub

Remove legacy restart support (#6801)

parent 83be3e59
......@@ -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<bool> runFromFile(ApplicationPackage package,
String scriptUri,
String packagesUri) async {
AndroidApk apk = package;
List<String> cmd = adbCommandForDevice(<String>[
'shell', 'am', 'start',
'-a', 'android.intent.action.RUN',
'-d', _deviceBundlePath,
'-f', '0x20000000', // FLAG_ACTIVITY_SINGLE_TOP
]);
cmd.addAll(<String>['--es', 'file', scriptUri]);
cmd.addAll(<String>['--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<bool> 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<bool> stopApp(ApplicationPackage app) {
List<String> command = adbCommandForDevice(<String>['shell', 'am', 'force-stop', app.id]);
......@@ -544,44 +469,6 @@ class AndroidDevice extends Device {
@override
bool isSupported() => true;
Future<bool> refreshSnapshot(String activity, String snapshotPath) async {
if (!FileSystemEntity.isFileSync(snapshotPath)) {
printError('Cannot find $snapshotPath');
return false;
}
RunResult result = await runAsync(
adbCommandForDevice(<String>['push', snapshotPath, _deviceSnapshotPath])
);
if (result.exitCode != 0) {
printStatus(result.toString());
return false;
}
List<String> cmd = adbCommandForDevice(<String>[
'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;
......
......@@ -386,7 +386,7 @@ class AppDomain extends Domain {
}
bool isRestartSupported(bool enableHotReload, Device device) =>
enableHotReload ? device.supportsHotMode : device.supportsRestart;
enableHotReload && device.supportsHotMode;
Future<OperationResult> restart(Map<String, dynamic> args) async {
String appId = _getStringArg(args, 'appId', required: true);
......
......@@ -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<bool> 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<bool> 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<bool> stopApp(ApplicationPackage app);
......
......@@ -443,6 +443,9 @@ class HotRunner extends ResidentRunner {
return true;
}
@override
bool get supportsRestart => true;
@override
Future<OperationResult> 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.');
......
......@@ -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<bool> restartApp(
ApplicationPackage package,
LaunchResult result, {
String mainPath,
VMService observatory,
bool prebuiltApplication: false
}) async {
throw 'unsupported';
}
@override
Future<bool> stopApp(ApplicationPackage app) async {
// Currently we don't have a way to stop an app running on iOS.
......
......@@ -45,7 +45,11 @@ abstract class ResidentRunner {
bool shouldBuild: true
});
Future<OperationResult> restart({ bool fullRestart: false, bool pauseAfterRestart: false });
bool get supportsRestart => false;
Future<OperationResult> restart({ bool fullRestart: false, bool pauseAfterRestart: false }) {
throw 'unsupported';
}
Future<Null> 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);
......
......@@ -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<OperationResult> 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<ServiceEvent> 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<int> _run({
bool traceStartup: false,
Completer<DebugConnectionInfo> connectionInfoCompleter,
......@@ -219,17 +183,7 @@ class RunAndStayResident extends ResidentRunner {
}
@override
Future<Null> 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<Null> handleTerminalCommand(String code) async => null;
@override
Future<Null> 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);
}
}
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