Commit 005724b1 authored by Devon Carew's avatar Devon Carew

Merge pull request #2257 from devoncarew/call_stop_from_run

add back a call to device.stop() from the run command
parents 0316b023 f9adbcf2
...@@ -234,6 +234,8 @@ class AdbDevice { ...@@ -234,6 +234,8 @@ class AdbDevice {
} }
} }
final RegExp _whitespaceRegex = new RegExp(r'\s+');
String cleanAdbDeviceName(String name) { String cleanAdbDeviceName(String name) {
// Some emulators use `___` in the name as separators. // Some emulators use `___` in the name as separators.
name = name.replaceAll('___', ', '); name = name.replaceAll('___', ', ');
...@@ -241,6 +243,8 @@ String cleanAdbDeviceName(String name) { ...@@ -241,6 +243,8 @@ String cleanAdbDeviceName(String name) {
// Convert `Nexus_7` / `Nexus_5X` style names to `Nexus 7` ones. // Convert `Nexus_7` / `Nexus_5X` style names to `Nexus 7` ones.
name = name.replaceAll('_', ' '); name = name.replaceAll('_', ' ');
name = name.replaceAll(_whitespaceRegex, ' ').trim();
return name; return name;
} }
......
...@@ -207,6 +207,7 @@ class AndroidDevice extends Device { ...@@ -207,6 +207,7 @@ class AndroidDevice extends Device {
this.clearLogs(); this.clearLogs();
runCheckedSync(adbCommandForDevice(<String>['push', bundlePath, _deviceBundlePath])); runCheckedSync(adbCommandForDevice(<String>['push', bundlePath, _deviceBundlePath]));
List<String> cmd = adbCommandForDevice(<String>[ List<String> cmd = adbCommandForDevice(<String>[
'shell', 'am', 'start', 'shell', 'am', 'start',
'-a', 'android.intent.action.RUN', '-a', 'android.intent.action.RUN',
...@@ -270,10 +271,9 @@ class AndroidDevice extends Device { ...@@ -270,10 +271,9 @@ class AndroidDevice extends Device {
} }
} }
Future<bool> stopApp(ApplicationPackage app) async { Future<bool> stopApp(ApplicationPackage app) {
final AndroidApk apk = app; List<String> command = adbCommandForDevice(<String>['shell', 'am', 'force-stop', app.id]);
runSync(adbCommandForDevice(<String>['shell', 'am', 'force-stop', apk.id])); return runCommandAndStreamOutput(command).then((int exitCode) => exitCode == 0);
return true;
} }
@override @override
......
...@@ -349,16 +349,20 @@ bool _needsRebuild(String apkPath, String manifest) { ...@@ -349,16 +349,20 @@ bool _needsRebuild(String apkPath, String manifest) {
Iterable<FileStat> dependenciesStat = [ Iterable<FileStat> dependenciesStat = [
manifest, manifest,
_kFlutterManifestPath, _kFlutterManifestPath,
_kPackagesStatusPath, _kPackagesStatusPath
'$apkPath.sha1'
].map((String path) => FileStat.statSync(path)); ].map((String path) => FileStat.statSync(path));
if (apkStat.type == FileSystemEntityType.NOT_FOUND) if (apkStat.type == FileSystemEntityType.NOT_FOUND)
return true; return true;
for (FileStat dep in dependenciesStat) { for (FileStat dep in dependenciesStat) {
if (dep.modified == null || dep.modified.isAfter(apkStat.modified)) if (dep.modified == null || dep.modified.isAfter(apkStat.modified))
return true; return true;
} }
if (!FileSystemEntity.isFileSync('$apkPath.sha1'))
return true;
return false; return false;
} }
......
...@@ -19,7 +19,6 @@ import '../toolchain.dart'; ...@@ -19,7 +19,6 @@ import '../toolchain.dart';
import 'apk.dart'; import 'apk.dart';
import 'devices.dart'; import 'devices.dart';
import 'install.dart'; import 'install.dart';
import 'stop.dart';
/// Given the value of the --target option, return the path of the Dart file /// Given the value of the --target option, return the path of the Dart file
/// where the app's main function should be. /// where the app's main function should be.
...@@ -65,7 +64,7 @@ class RunCommand extends RunCommandBase { ...@@ -65,7 +64,7 @@ class RunCommand extends RunCommandBase {
RunCommand() { RunCommand() {
argParser.addFlag('full-restart', argParser.addFlag('full-restart',
defaultsTo: false, defaultsTo: true,
help: 'Stop any currently running application process before starting the app.'); help: 'Stop any currently running application process before starting the app.');
argParser.addFlag('clear-logs', argParser.addFlag('clear-logs',
defaultsTo: true, defaultsTo: true,
...@@ -111,6 +110,7 @@ class RunCommand extends RunCommandBase { ...@@ -111,6 +110,7 @@ class RunCommand extends RunCommandBase {
return 1; return 1;
} }
// TODO(devoncarew): Switch this to using [devicesForCommand].
int result = await startApp( int result = await startApp(
devices, devices,
applicationPackages, applicationPackages,
...@@ -140,7 +140,7 @@ Future<int> startApp( ...@@ -140,7 +140,7 @@ Future<int> startApp(
List<BuildConfiguration> configs, { List<BuildConfiguration> configs, {
String target, String target,
String enginePath, String enginePath,
bool stop: false, bool stop: true,
bool install: true, bool install: true,
bool checked: true, bool checked: true,
bool traceStartup: false, bool traceStartup: false,
...@@ -169,11 +169,27 @@ Future<int> startApp( ...@@ -169,11 +169,27 @@ Future<int> startApp(
return result; return result;
} }
// TODO(devoncarew): Move this into the device.startApp() impls. They should
// wait on the stop command to complete before (re-)starting the app. We could
// plumb a Future through the start command from here, but that seems a little
// messy.
if (stop) { if (stop) {
printTrace('Running stop command.'); for (Device device in devices.all) {
await stopAll(devices, applicationPackages); if (!device.isSupported())
continue;
ApplicationPackage package = applicationPackages.getPackageForPlatform(device.platform);
if (package != null) {
printTrace("Stopping app '${package.name}' on ${device.name}.");
// We don't wait for the stop command to complete.
device.stopApp(package);
}
}
} }
// Allow any stop commands from above to start work.
await new Future.delayed(Duration.ZERO);
if (install) { if (install) {
printTrace('Running install command.'); printTrace('Running install command.');
// TODO(devoncarew): This fails for ios devices - we haven't built yet. // TODO(devoncarew): This fails for ios devices - we haven't built yet.
...@@ -194,8 +210,6 @@ Future<int> startApp( ...@@ -194,8 +210,6 @@ Future<int> startApp(
continue; continue;
} }
printTrace('Running build command for $device.');
Map<String, dynamic> platformArgs = <String, dynamic>{}; Map<String, dynamic> platformArgs = <String, dynamic>{};
if (traceStartup != null) if (traceStartup != null)
...@@ -223,9 +237,8 @@ Future<int> startApp( ...@@ -223,9 +237,8 @@ Future<int> startApp(
// If the user specified --start-paused (and the device supports it) then // If the user specified --start-paused (and the device supports it) then
// wait for the observatory port to become available before returning from // wait for the observatory port to become available before returning from
// `startApp()`. // `startApp()`.
if (startPaused && device.supportsStartPaused) { if (startPaused && device.supportsStartPaused)
await delayUntilObservatoryAvailable('localhost', debugPort); await delayUntilObservatoryAvailable('localhost', debugPort);
}
} }
} }
......
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