Commit 98016b1c authored by John McCutchan's avatar John McCutchan Committed by GitHub

Cleanup application startup on Android devices (#6949)

- [x] Stop unnecessarily building the flx a second time on startup.
- [x] Stop unncessarily copying the flx to the device a second time on startup.
- [x] Remove `startBundle` and move logic into `startApp`.
parent 9c1a24fa
...@@ -13,7 +13,6 @@ import '../base/logger.dart'; ...@@ -13,7 +13,6 @@ import '../base/logger.dart';
import '../base/process.dart'; import '../base/process.dart';
import '../build_info.dart'; import '../build_info.dart';
import '../device.dart'; import '../device.dart';
import '../flx.dart' as flx;
import '../globals.dart'; import '../globals.dart';
import '../protocol_discovery.dart'; import '../protocol_discovery.dart';
import 'adb.dart'; import 'adb.dart';
...@@ -22,10 +21,6 @@ import 'android_sdk.dart'; ...@@ -22,10 +21,6 @@ import 'android_sdk.dart';
const String _defaultAdbPath = 'adb'; const String _defaultAdbPath = 'adb';
// Path where the FLX bundle will be copied on the device.
const String _deviceBundlePath = '/data/local/tmp/dev.flx';
class AndroidDevices extends PollingDeviceDiscovery { class AndroidDevices extends PollingDeviceDiscovery {
AndroidDevices() : super('AndroidDevices'); AndroidDevices() : super('AndroidDevices');
...@@ -274,60 +269,49 @@ class AndroidDevice extends Device { ...@@ -274,60 +269,49 @@ class AndroidDevice extends Device {
return null; return null;
} }
Future<LaunchResult> startBundle(AndroidApk apk, String bundlePath, { @override
bool traceStartup: false, Future<LaunchResult> startApp(
ApplicationPackage package,
BuildMode mode, {
String mainPath,
String route, String route,
DebuggingOptions options DebuggingOptions debuggingOptions,
Map<String, dynamic> platformArgs,
bool prebuiltApplication: false
}) async { }) async {
printTrace('$this startBundle'); if (!_checkForSupportedAdbVersion() || !_checkForSupportedAndroidVersion())
if (bundlePath != null) {
if (!FileSystemEntity.isFileSync(bundlePath)) {
printError('Cannot find $bundlePath');
return new LaunchResult.failed(); return new LaunchResult.failed();
}
runCheckedSync( final bool traceStartup = platformArgs['trace-startup'] ?? false;
adbCommandForDevice(<String>['push', bundlePath, _deviceBundlePath])); final AndroidApk apk = package;
} printTrace('$this startApp');
ProtocolDiscovery observatoryDiscovery; ProtocolDiscovery observatoryDiscovery;
ProtocolDiscovery diagnosticDiscovery; ProtocolDiscovery diagnosticDiscovery;
DeviceLogReader logReader = getLogReader(); DeviceLogReader logReader = getLogReader();
if (options.debuggingEnabled) { if (debuggingOptions.debuggingEnabled) {
observatoryDiscovery = new ProtocolDiscovery(logReader, ProtocolDiscovery.kObservatoryService); observatoryDiscovery = new ProtocolDiscovery(logReader, ProtocolDiscovery.kObservatoryService);
diagnosticDiscovery = new ProtocolDiscovery(logReader, ProtocolDiscovery.kDiagnosticService); diagnosticDiscovery = new ProtocolDiscovery(logReader, ProtocolDiscovery.kDiagnosticService);
} }
List<String> cmd; List<String> cmd;
if (bundlePath != null) {
// Specify in the RUN intent the path to the local bundle pushed.
cmd = adbCommandForDevice(<String>[ cmd = adbCommandForDevice(<String>[
'shell', 'am', 'start', 'shell', 'am', 'start',
'-a', 'android.intent.action.RUN', '-a', 'android.intent.action.RUN',
'-d', _deviceBundlePath,
'-f', '0x20000000', // FLAG_ACTIVITY_SINGLE_TOP '-f', '0x20000000', // FLAG_ACTIVITY_SINGLE_TOP
'--ez', 'enable-background-compilation', 'true', '--ez', 'enable-background-compilation', 'true',
]); ]);
} else {
cmd = adbCommandForDevice(<String>[
'shell', 'am', 'start',
'-a', 'android.intent.action.RUN',
'-f', '0x20000000', // FLAG_ACTIVITY_SINGLE_TOP
'--ez', 'enable-background-compilation', 'true',
]);
}
if (traceStartup) if (traceStartup)
cmd.addAll(<String>['--ez', 'trace-startup', 'true']); cmd.addAll(<String>['--ez', 'trace-startup', 'true']);
if (route != null) if (route != null)
cmd.addAll(<String>['--es', 'route', route]); cmd.addAll(<String>['--es', 'route', route]);
if (options.debuggingEnabled) { if (debuggingOptions.debuggingEnabled) {
if (options.buildMode == BuildMode.debug) if (debuggingOptions.buildMode == BuildMode.debug)
cmd.addAll(<String>['--ez', 'enable-checked-mode', 'true']); cmd.addAll(<String>['--ez', 'enable-checked-mode', 'true']);
if (options.startPaused) if (debuggingOptions.startPaused)
cmd.addAll(<String>['--ez', 'start-paused', 'true']); cmd.addAll(<String>['--ez', 'start-paused', 'true']);
} }
cmd.add(apk.launchActivity); cmd.add(apk.launchActivity);
...@@ -338,7 +322,7 @@ class AndroidDevice extends Device { ...@@ -338,7 +322,7 @@ class AndroidDevice extends Device {
return new LaunchResult.failed(); return new LaunchResult.failed();
} }
if (!options.debuggingEnabled) { if (!debuggingOptions.debuggingEnabled) {
return new LaunchResult.succeeded(); return new LaunchResult.succeeded();
} else { } else {
// Wait for the service protocol port here. This will complete once the // Wait for the service protocol port here. This will complete once the
...@@ -348,7 +332,7 @@ class AndroidDevice extends Device { ...@@ -348,7 +332,7 @@ class AndroidDevice extends Device {
try { try {
int observatoryDevicePort, diagnosticDevicePort; int observatoryDevicePort, diagnosticDevicePort;
if (options.buildMode == BuildMode.debug) { if (debuggingOptions.buildMode == BuildMode.debug) {
Future<List<int>> scrapeServicePorts = Future.wait( Future<List<int>> scrapeServicePorts = Future.wait(
<Future<int>>[observatoryDiscovery.nextPort(), diagnosticDiscovery.nextPort()] <Future<int>>[observatoryDiscovery.nextPort(), diagnosticDiscovery.nextPort()]
); );
...@@ -360,7 +344,7 @@ class AndroidDevice extends Device { ...@@ -360,7 +344,7 @@ class AndroidDevice extends Device {
} }
printTrace('observatory port on device: $observatoryDevicePort'); printTrace('observatory port on device: $observatoryDevicePort');
int observatoryLocalPort = await options.findBestObservatoryPort(); int observatoryLocalPort = await debuggingOptions.findBestObservatoryPort();
// TODO(devoncarew): Remember the forwarding information (so we can later remove the // TODO(devoncarew): Remember the forwarding information (so we can later remove the
// port forwarding). // port forwarding).
observatoryLocalPort = await _forwardPort(ProtocolDiscovery.kObservatoryService, observatoryDevicePort, observatoryLocalPort); observatoryLocalPort = await _forwardPort(ProtocolDiscovery.kObservatoryService, observatoryDevicePort, observatoryLocalPort);
...@@ -368,7 +352,7 @@ class AndroidDevice extends Device { ...@@ -368,7 +352,7 @@ class AndroidDevice extends Device {
int diagnosticLocalPort; int diagnosticLocalPort;
if (diagnosticDevicePort != null) { if (diagnosticDevicePort != null) {
printTrace('diagnostic port on device: $diagnosticDevicePort'); printTrace('diagnostic port on device: $diagnosticDevicePort');
diagnosticLocalPort = await options.findBestDiagnosticPort(); diagnosticLocalPort = await debuggingOptions.findBestDiagnosticPort();
diagnosticLocalPort = await _forwardPort(ProtocolDiscovery.kDiagnosticService, diagnosticDevicePort, diagnosticLocalPort); diagnosticLocalPort = await _forwardPort(ProtocolDiscovery.kDiagnosticService, diagnosticDevicePort, diagnosticLocalPort);
} }
...@@ -389,42 +373,6 @@ class AndroidDevice extends Device { ...@@ -389,42 +373,6 @@ class AndroidDevice extends Device {
} }
} }
@override
Future<LaunchResult> startApp(
ApplicationPackage package,
BuildMode mode, {
String mainPath,
String route,
DebuggingOptions debuggingOptions,
Map<String, dynamic> platformArgs,
bool prebuiltApplication: false
}) async {
if (!_checkForSupportedAdbVersion() || !_checkForSupportedAndroidVersion())
return new LaunchResult.failed();
String localBundlePath;
if (!prebuiltApplication) {
localBundlePath = await flx.buildFlx(
mainPath: mainPath,
precompiledSnapshot: isAotBuildMode(debuggingOptions.buildMode),
includeRobotoFonts: false
);
if (localBundlePath == null)
return new LaunchResult.failed();
}
printTrace('Starting bundle for $this.');
return startBundle(
package,
localBundlePath,
traceStartup: platformArgs['trace-startup'] ?? false,
route: route,
options: debuggingOptions
);
}
@override @override
bool get supportsHotMode => true; bool get supportsHotMode => true;
......
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