Commit 5bce2fbd authored by Devon Carew's avatar Devon Carew

refactor platform specific code out of device.dart

remove device type specific checks
parent 0f505fbf
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
const int minApiLevel = 16;
const String minVersionName = 'Jelly Bean';
const String minVersionText = '4.1.x';
This diff is collapsed.
...@@ -9,12 +9,12 @@ import 'dart:io'; ...@@ -9,12 +9,12 @@ import 'dart:io';
import 'package:path/path.dart' as path; import 'package:path/path.dart' as path;
import 'package:yaml/yaml.dart'; import 'package:yaml/yaml.dart';
import '../android/device_android.dart';
import '../artifacts.dart'; import '../artifacts.dart';
import '../base/file_system.dart'; import '../base/file_system.dart';
import '../base/logging.dart'; import '../base/logging.dart';
import '../base/process.dart'; import '../base/process.dart';
import '../build_configuration.dart'; import '../build_configuration.dart';
import '../device.dart';
import '../flx.dart' as flx; import '../flx.dart' as flx;
import '../runner/flutter_command.dart'; import '../runner/flutter_command.dart';
import 'start.dart'; import 'start.dart';
...@@ -392,16 +392,13 @@ class ApkCommand extends FlutterCommand { ...@@ -392,16 +392,13 @@ class ApkCommand extends FlutterCommand {
String mainPath = findMainDartFile(argResults['target']); String mainPath = findMainDartFile(argResults['target']);
// Build the FLX. // Build the FLX.
int result; flx.DirectoryResult buildResult = await flx.buildInTempDir(toolchain, mainPath: mainPath);
await flx.buildInTempDir(
toolchain,
mainPath: mainPath,
onBundleAvailable: (String localBundlePath) {
result = _buildApk(components, localBundlePath);
}
);
return result; try {
return _buildApk(components, buildResult.localBundlePath);
} finally {
buildResult.dispose();
}
} }
} }
} }
...@@ -7,6 +7,7 @@ import 'dart:convert'; ...@@ -7,6 +7,7 @@ import 'dart:convert';
import 'dart:io'; import 'dart:io';
import '../android/adb.dart'; import '../android/adb.dart';
import '../android/device_android.dart';
import '../base/logging.dart'; import '../base/logging.dart';
import '../device.dart'; import '../device.dart';
import '../runner/flutter_command.dart'; import '../runner/flutter_command.dart';
......
...@@ -9,10 +9,10 @@ import 'package:args/command_runner.dart'; ...@@ -9,10 +9,10 @@ import 'package:args/command_runner.dart';
import 'package:mustache4dart/mustache4dart.dart' as mustache; import 'package:mustache4dart/mustache4dart.dart' as mustache;
import 'package:path/path.dart' as path; import 'package:path/path.dart' as path;
import '../android/android.dart' as android;
import '../artifacts.dart'; import '../artifacts.dart';
import '../base/logging.dart'; import '../base/logging.dart';
import '../base/process.dart'; import '../base/process.dart';
import '../device.dart';
class InitCommand extends Command { class InitCommand extends Command {
final String name = 'init'; final String name = 'init';
...@@ -247,7 +247,7 @@ final String _apkManifest = ''' ...@@ -247,7 +247,7 @@ final String _apkManifest = '''
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.{{projectName}}"> package="com.example.{{projectName}}">
<uses-sdk android:minSdkVersion="${AndroidDevice.minApiLevel}" android:targetSdkVersion="21" /> <uses-sdk android:minSdkVersion="${android.minApiLevel}" android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.INTERNET"/>
<application android:name="org.domokit.sky.shell.SkyApplication" android:label="{{projectName}}"> <application android:name="org.domokit.sky.shell.SkyApplication" android:label="{{projectName}}">
......
...@@ -4,7 +4,8 @@ ...@@ -4,7 +4,8 @@
import 'dart:async'; import 'dart:async';
import '../device.dart'; import '../android/device_android.dart';
import '../ios/device_ios.dart';
import '../runner/flutter_command.dart'; import '../runner/flutter_command.dart';
class ListCommand extends FlutterCommand { class ListCommand extends FlutterCommand {
...@@ -29,6 +30,8 @@ class ListCommand extends FlutterCommand { ...@@ -29,6 +30,8 @@ class ListCommand extends FlutterCommand {
if (details) if (details)
print('Android Devices:'); print('Android Devices:');
// TODO(devoncarew): We should have a more generic mechanism for device discovery.
// DeviceDiscoveryService? DeviceDiscoveryParticipant?
for (AndroidDevice device in AndroidDevice.getAttachedDevices(devices.android)) { for (AndroidDevice device in AndroidDevice.getAttachedDevices(devices.android)) {
if (details) { if (details) {
print('${device.id}\t' print('${device.id}\t'
......
...@@ -9,9 +9,7 @@ import 'package:path/path.dart' as path; ...@@ -9,9 +9,7 @@ import 'package:path/path.dart' as path;
import '../application_package.dart'; import '../application_package.dart';
import '../base/logging.dart'; import '../base/logging.dart';
import '../build_configuration.dart';
import '../device.dart'; import '../device.dart';
import '../flx.dart' as flx;
import '../runner/flutter_command.dart'; import '../runner/flutter_command.dart';
import '../toolchain.dart'; import '../toolchain.dart';
import 'install.dart'; import 'install.dart';
...@@ -138,31 +136,28 @@ Future<int> startApp( ...@@ -138,31 +136,28 @@ Future<int> startApp(
logging.fine('Running build command for $device.'); logging.fine('Running build command for $device.');
if (device.platform == TargetPlatform.android) { Map<String, dynamic> platformArgs = <String, dynamic>{};
await flx.buildInTempDir(
toolchain, if (poke != null)
mainPath: mainPath, platformArgs['poke'] = poke;
onBundleAvailable: (String localBundlePath) { if (traceStartup != null)
logging.fine('Starting bundle for $device.'); platformArgs['trace-startup'] = traceStartup;
final AndroidDevice androidDevice = device; // https://github.com/flutter/flutter/issues/1035 if (clearLogs != null)
if (androidDevice.startBundle(package, localBundlePath, platformArgs['clear-logs'] = clearLogs;
poke: poke,
checked: checked, bool result = await device.startApp(
traceStartup: traceStartup, package,
route: route, toolchain,
clearLogs: clearLogs mainPath: mainPath,
)) { route: route,
startedSomething = true; checked: checked,
} platformArgs: platformArgs
} );
);
if (!result) {
logging.severe('Could not start \'${package.name}\' on \'${device.id}\'');
} else { } else {
bool result = await device.startApp(package); startedSomething = true;
if (!result) {
logging.severe('Could not start \'${package.name}\' on \'${device.id}\'');
} else {
startedSomething = true;
}
} }
} }
......
...@@ -4,9 +4,9 @@ ...@@ -4,9 +4,9 @@
import 'dart:async'; import 'dart:async';
import '../android/device_android.dart';
import '../application_package.dart'; import '../application_package.dart';
import '../base/logging.dart'; import '../base/logging.dart';
import '../device.dart';
import '../runner/flutter_command.dart'; import '../runner/flutter_command.dart';
class TraceCommand extends FlutterCommand { class TraceCommand extends FlutterCommand {
......
This diff is collapsed.
...@@ -114,28 +114,38 @@ ArchiveFile _createSnapshotFile(String snapshotPath) { ...@@ -114,28 +114,38 @@ ArchiveFile _createSnapshotFile(String snapshotPath) {
return new ArchiveFile(_kSnapshotKey, content.length, content); return new ArchiveFile(_kSnapshotKey, content.length, content);
} }
Future<int> buildInTempDir( /// Build the flx in a temp dir and return `localBundlePath` on success.
Future<DirectoryResult> buildInTempDir(
Toolchain toolchain, { Toolchain toolchain, {
String mainPath: defaultMainPath, String mainPath: defaultMainPath
void onBundleAvailable(String bundlePath)
}) async { }) async {
int result; int result;
Directory tempDir = await Directory.systemTemp.createTemp('flutter_tools'); Directory tempDir = await Directory.systemTemp.createTemp('flutter_tools');
try { String localBundlePath = path.join(tempDir.path, 'app.flx');
String localBundlePath = path.join(tempDir.path, 'app.flx'); String localSnapshotPath = path.join(tempDir.path, 'snapshot_blob.bin');
String localSnapshotPath = path.join(tempDir.path, 'snapshot_blob.bin'); result = await build(
result = await build( toolchain,
toolchain, snapshotPath: localSnapshotPath,
snapshotPath: localSnapshotPath, outputPath: localBundlePath,
outputPath: localBundlePath, mainPath: mainPath
mainPath: mainPath );
); if (result == 0)
if (result == 0) return new DirectoryResult(tempDir, localBundlePath);
onBundleAvailable(localBundlePath); else
} finally { throw result;
tempDir.deleteSync(recursive: true); }
/// The result from [buildInTempDir]. Note that this object should be disposed after use.
class DirectoryResult {
final Directory directory;
final String localBundlePath;
DirectoryResult(this.directory, this.localBundlePath);
/// Call this to delete the temporary directory.
void dispose() {
directory.deleteSync(recursive: true);
} }
return result;
} }
Future<int> build( Future<int> build(
......
This diff is collapsed.
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'package:flutter_tools/src/device.dart'; import 'package:flutter_tools/src/android/device_android.dart';
import 'package:test/test.dart'; import 'package:test/test.dart';
main() => defineTests(); main() => defineTests();
......
...@@ -2,9 +2,11 @@ ...@@ -2,9 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'package:flutter_tools/src/android/device_android.dart';
import 'package:flutter_tools/src/application_package.dart'; import 'package:flutter_tools/src/application_package.dart';
import 'package:flutter_tools/src/build_configuration.dart'; import 'package:flutter_tools/src/build_configuration.dart';
import 'package:flutter_tools/src/device.dart'; import 'package:flutter_tools/src/device.dart';
import 'package:flutter_tools/src/ios/device_ios.dart';
import 'package:flutter_tools/src/runner/flutter_command.dart'; import 'package:flutter_tools/src/runner/flutter_command.dart';
import 'package:flutter_tools/src/toolchain.dart'; import 'package:flutter_tools/src/toolchain.dart';
import 'package:mockito/mockito.dart'; import 'package:mockito/mockito.dart';
......
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