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';
import 'package:path/path.dart' as path;
import 'package:yaml/yaml.dart';
import '../android/device_android.dart';
import '../artifacts.dart';
import '../base/file_system.dart';
import '../base/logging.dart';
import '../base/process.dart';
import '../build_configuration.dart';
import '../device.dart';
import '../flx.dart' as flx;
import '../runner/flutter_command.dart';
import 'start.dart';
......@@ -392,16 +392,13 @@ class ApkCommand extends FlutterCommand {
String mainPath = findMainDartFile(argResults['target']);
// Build the FLX.
int result;
await flx.buildInTempDir(
toolchain,
mainPath: mainPath,
onBundleAvailable: (String localBundlePath) {
result = _buildApk(components, localBundlePath);
}
);
flx.DirectoryResult buildResult = await flx.buildInTempDir(toolchain, mainPath: mainPath);
return result;
try {
return _buildApk(components, buildResult.localBundlePath);
} finally {
buildResult.dispose();
}
}
}
}
......@@ -7,6 +7,7 @@ import 'dart:convert';
import 'dart:io';
import '../android/adb.dart';
import '../android/device_android.dart';
import '../base/logging.dart';
import '../device.dart';
import '../runner/flutter_command.dart';
......
......@@ -9,10 +9,10 @@ import 'package:args/command_runner.dart';
import 'package:mustache4dart/mustache4dart.dart' as mustache;
import 'package:path/path.dart' as path;
import '../android/android.dart' as android;
import '../artifacts.dart';
import '../base/logging.dart';
import '../base/process.dart';
import '../device.dart';
class InitCommand extends Command {
final String name = 'init';
......@@ -247,7 +247,7 @@ final String _apkManifest = '''
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
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"/>
<application android:name="org.domokit.sky.shell.SkyApplication" android:label="{{projectName}}">
......
......@@ -4,7 +4,8 @@
import 'dart:async';
import '../device.dart';
import '../android/device_android.dart';
import '../ios/device_ios.dart';
import '../runner/flutter_command.dart';
class ListCommand extends FlutterCommand {
......@@ -29,6 +30,8 @@ class ListCommand extends FlutterCommand {
if (details)
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)) {
if (details) {
print('${device.id}\t'
......
......@@ -9,9 +9,7 @@ import 'package:path/path.dart' as path;
import '../application_package.dart';
import '../base/logging.dart';
import '../build_configuration.dart';
import '../device.dart';
import '../flx.dart' as flx;
import '../runner/flutter_command.dart';
import '../toolchain.dart';
import 'install.dart';
......@@ -138,31 +136,28 @@ Future<int> startApp(
logging.fine('Running build command for $device.');
if (device.platform == TargetPlatform.android) {
await flx.buildInTempDir(
toolchain,
mainPath: mainPath,
onBundleAvailable: (String localBundlePath) {
logging.fine('Starting bundle for $device.');
final AndroidDevice androidDevice = device; // https://github.com/flutter/flutter/issues/1035
if (androidDevice.startBundle(package, localBundlePath,
poke: poke,
checked: checked,
traceStartup: traceStartup,
route: route,
clearLogs: clearLogs
)) {
startedSomething = true;
}
}
);
Map<String, dynamic> platformArgs = <String, dynamic>{};
if (poke != null)
platformArgs['poke'] = poke;
if (traceStartup != null)
platformArgs['trace-startup'] = traceStartup;
if (clearLogs != null)
platformArgs['clear-logs'] = clearLogs;
bool result = await device.startApp(
package,
toolchain,
mainPath: mainPath,
route: route,
checked: checked,
platformArgs: platformArgs
);
if (!result) {
logging.severe('Could not start \'${package.name}\' on \'${device.id}\'');
} else {
bool result = await device.startApp(package);
if (!result) {
logging.severe('Could not start \'${package.name}\' on \'${device.id}\'');
} else {
startedSomething = true;
}
startedSomething = true;
}
}
......
......@@ -4,9 +4,9 @@
import 'dart:async';
import '../android/device_android.dart';
import '../application_package.dart';
import '../base/logging.dart';
import '../device.dart';
import '../runner/flutter_command.dart';
class TraceCommand extends FlutterCommand {
......
This diff is collapsed.
......@@ -114,28 +114,38 @@ ArchiveFile _createSnapshotFile(String snapshotPath) {
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, {
String mainPath: defaultMainPath,
void onBundleAvailable(String bundlePath)
String mainPath: defaultMainPath
}) async {
int result;
Directory tempDir = await Directory.systemTemp.createTemp('flutter_tools');
try {
String localBundlePath = path.join(tempDir.path, 'app.flx');
String localSnapshotPath = path.join(tempDir.path, 'snapshot_blob.bin');
result = await build(
toolchain,
snapshotPath: localSnapshotPath,
outputPath: localBundlePath,
mainPath: mainPath
);
if (result == 0)
onBundleAvailable(localBundlePath);
} finally {
tempDir.deleteSync(recursive: true);
String localBundlePath = path.join(tempDir.path, 'app.flx');
String localSnapshotPath = path.join(tempDir.path, 'snapshot_blob.bin');
result = await build(
toolchain,
snapshotPath: localSnapshotPath,
outputPath: localBundlePath,
mainPath: mainPath
);
if (result == 0)
return new DirectoryResult(tempDir, localBundlePath);
else
throw result;
}
/// 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(
......
This diff is collapsed.
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// 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';
main() => defineTests();
......
......@@ -2,9 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// 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/build_configuration.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/toolchain.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