add back a call to device.stop() from the run command

This commit is contained in:
Devon Carew 2016-02-27 19:32:02 -08:00
parent 0316b0233e
commit d326991b97
4 changed files with 35 additions and 15 deletions

View file

@ -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) {
// 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;
} }

View file

@ -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 {
} }
} }
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

View file

@ -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;
} }

View file

@ -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 {
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 {
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(
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,10 +169,25 @@ Future<int> startApp(
return result; return result;
} }
// TODO: Move this into the startApp() device impl. 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.');
@ -194,8 +209,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,11 +236,10 @@ 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);
} }
} }
}
if (!startedSomething) { if (!startedSomething) {
String message = 'Unable to run application'; String message = 'Unable to run application';