Commit 3298f874 authored by Devon Carew's avatar Devon Carew

Merge pull request #2226 from devoncarew/remove_connected

remove the isConnected() method from device
parents 19b9464e 022047f5
...@@ -41,19 +41,13 @@ class AndroidDevice extends Device { ...@@ -41,19 +41,13 @@ class AndroidDevice extends Device {
String id, { String id, {
this.productID, this.productID,
this.modelID, this.modelID,
this.deviceCodeName, this.deviceCodeName
bool connected }) : super(id);
}) : super(id) {
if (connected != null)
_connected = connected;
}
final String productID; final String productID;
final String modelID; final String modelID;
final String deviceCodeName; final String deviceCodeName;
bool _connected;
bool get isLocalEmulator => false; bool get isLocalEmulator => false;
List<String> adbCommandForDevice(List<String> args) { List<String> adbCommandForDevice(List<String> args) {
...@@ -152,9 +146,6 @@ class AndroidDevice extends Device { ...@@ -152,9 +146,6 @@ class AndroidDevice extends Device {
@override @override
bool isAppInstalled(ApplicationPackage app) { bool isAppInstalled(ApplicationPackage app) {
if (!isConnected())
return false;
if (runCheckedSync(adbCommandForDevice(<String>['shell', 'pm', 'path', app.id])) == '') { if (runCheckedSync(adbCommandForDevice(<String>['shell', 'pm', 'path', app.id])) == '') {
printTrace('TODO(iansf): move this log to the caller. ${app.name} is not on the device. Installing now...'); printTrace('TODO(iansf): move this log to the caller. ${app.name} is not on the device. Installing now...');
return false; return false;
...@@ -169,11 +160,6 @@ class AndroidDevice extends Device { ...@@ -169,11 +160,6 @@ class AndroidDevice extends Device {
@override @override
bool installApp(ApplicationPackage app) { bool installApp(ApplicationPackage app) {
if (!isConnected()) {
printTrace('Android device not connected. Not installing.');
return false;
}
if (!FileSystemEntity.isFileSync(app.localPath)) { if (!FileSystemEntity.isFileSync(app.localPath)) {
printError('"${app.localPath}" does not exist.'); printError('"${app.localPath}" does not exist.');
return false; return false;
...@@ -390,14 +376,8 @@ class AndroidDevice extends Device { ...@@ -390,14 +376,8 @@ class AndroidDevice extends Device {
return null; return null;
} }
bool isConnected() => _connected ?? androidSdk != null;
bool isSupported() => true; bool isSupported() => true;
void setConnected(bool value) {
_connected = value;
}
Future<bool> refreshSnapshot(AndroidApk apk, String snapshotPath) async { Future<bool> refreshSnapshot(AndroidApk apk, String snapshotPath) async {
if (!FileSystemEntity.isFileSync(snapshotPath)) { if (!FileSystemEntity.isFileSync(snapshotPath)) {
printError('Cannot find $snapshotPath'); printError('Cannot find $snapshotPath');
...@@ -462,13 +442,12 @@ List<AndroidDevice> getAdbDevices() { ...@@ -462,13 +442,12 @@ List<AndroidDevice> getAdbDevices() {
deviceID, deviceID,
productID: productID, productID: productID,
modelID: modelID, modelID: modelID,
deviceCodeName: deviceCodeName, deviceCodeName: deviceCodeName
connected: true
)); ));
} else if (deviceRegex2.hasMatch(line)) { } else if (deviceRegex2.hasMatch(line)) {
Match match = deviceRegex2.firstMatch(line); Match match = deviceRegex2.firstMatch(line);
String deviceID = match[1]; String deviceID = match[1];
devices.add(new AndroidDevice(deviceID, connected: true)); devices.add(new AndroidDevice(deviceID));
} else if (unauthorizedRegex.hasMatch(line)) { } else if (unauthorizedRegex.hasMatch(line)) {
Match match = unauthorizedRegex.firstMatch(line); Match match = unauthorizedRegex.firstMatch(line);
String deviceID = match[1]; String deviceID = match[1];
...@@ -499,9 +478,6 @@ class _AdbLogReader extends DeviceLogReader { ...@@ -499,9 +478,6 @@ class _AdbLogReader extends DeviceLogReader {
String get name => device.name; String get name => device.name;
Future<int> logs({ bool clear: false, bool showPrefix: false }) async { Future<int> logs({ bool clear: false, bool showPrefix: false }) async {
if (!device.isConnected())
return 2;
if (clear) if (clear)
device.clearLogs(); device.clearLogs();
......
...@@ -430,7 +430,7 @@ Future<int> buildAll( ...@@ -430,7 +430,7 @@ Future<int> buildAll(
}) async { }) async {
for (Device device in devices.all) { for (Device device in devices.all) {
ApplicationPackage package = applicationPackages.getPackageForPlatform(device.platform); ApplicationPackage package = applicationPackages.getPackageForPlatform(device.platform);
if (package == null || !device.isConnected()) if (package == null)
continue; continue;
// TODO(mpcomplete): Temporary hack. We only support the apk builder atm. // TODO(mpcomplete): Temporary hack. We only support the apk builder atm.
......
...@@ -347,7 +347,7 @@ Map<String, dynamic> _deviceToMap(Device device) { ...@@ -347,7 +347,7 @@ Map<String, dynamic> _deviceToMap(Device device) {
'id': device.id, 'id': device.id,
'name': device.name, 'name': device.name,
'platform': _enumToString(device.platform), 'platform': _enumToString(device.platform),
'available': device.isConnected() 'available': true
}; };
} }
......
...@@ -30,7 +30,7 @@ Future<bool> installApp( ...@@ -30,7 +30,7 @@ Future<bool> installApp(
for (Device device in devices.all) { for (Device device in devices.all) {
ApplicationPackage package = applicationPackages.getPackageForPlatform(device.platform); ApplicationPackage package = applicationPackages.getPackageForPlatform(device.platform);
if (package == null || !device.isConnected() || device.isAppInstalled(package)) if (package == null || device.isAppInstalled(package))
continue; continue;
if (device.installApp(package)) if (device.installApp(package))
installedSomewhere = true; installedSomewhere = true;
......
...@@ -36,7 +36,7 @@ class RefreshCommand extends FlutterCommand { ...@@ -36,7 +36,7 @@ class RefreshCommand extends FlutterCommand {
downloadApplicationPackagesAndConnectToDevices(), downloadApplicationPackagesAndConnectToDevices(),
], eagerError: true); ], eagerError: true);
if (devices.android == null || !devices.android.isConnected()) { if (devices.android == null) {
printError('No device connected.'); printError('No device connected.');
return 1; return 1;
} }
......
...@@ -185,7 +185,7 @@ Future<int> startApp( ...@@ -185,7 +185,7 @@ Future<int> startApp(
for (Device device in devices.all) { for (Device device in devices.all) {
ApplicationPackage package = applicationPackages.getPackageForPlatform(device.platform); ApplicationPackage package = applicationPackages.getPackageForPlatform(device.platform);
if (package == null || !device.isConnected()) if (package == null)
continue; continue;
if (!device.isSupported()) { if (!device.isSupported()) {
...@@ -230,13 +230,14 @@ Future<int> startApp( ...@@ -230,13 +230,14 @@ Future<int> startApp(
} }
if (!startedSomething) { if (!startedSomething) {
int connected = devices.all.where((device) => device.isConnected()).length;
String message = 'Unable to run application'; String message = 'Unable to run application';
if (connected == 0) {
if (devices.all.isEmpty) {
message += ' - no connected devices.'; message += ' - no connected devices.';
} else if (unsupportedCount != 0) { } else if (unsupportedCount != 0) {
message += ' - $unsupportedCount unsupported ${pluralize('device', unsupportedCount)} connected'; message += ' - $unsupportedCount unsupported ${pluralize('device', unsupportedCount)} connected';
} }
printError(message); printError(message);
} }
......
...@@ -26,7 +26,7 @@ Future<bool> stopAll(DeviceStore devices, ApplicationPackageStore applicationPac ...@@ -26,7 +26,7 @@ Future<bool> stopAll(DeviceStore devices, ApplicationPackageStore applicationPac
for (Device device in devices.all) { for (Device device in devices.all) {
ApplicationPackage package = applicationPackages.getPackageForPlatform(device.platform); ApplicationPackage package = applicationPackages.getPackageForPlatform(device.platform);
if (package == null || !device.isConnected()) if (package == null)
continue; continue;
if (await device.stopApp(package)) if (await device.stopApp(package))
stoppedSomething = true; stoppedSomething = true;
......
...@@ -33,7 +33,7 @@ class TraceCommand extends FlutterCommand { ...@@ -33,7 +33,7 @@ class TraceCommand extends FlutterCommand {
Future<int> runInProject() async { Future<int> runInProject() async {
await downloadApplicationPackagesAndConnectToDevices(); await downloadApplicationPackagesAndConnectToDevices();
if (devices.android == null || !devices.android.isConnected()) { if (devices.android == null) {
printError('No device connected, so no trace was completed.'); printError('No device connected, so no trace was completed.');
return 1; return 1;
} }
......
...@@ -136,9 +136,6 @@ abstract class Device { ...@@ -136,9 +136,6 @@ abstract class Device {
/// Install an app package on the current device /// Install an app package on the current device
bool installApp(ApplicationPackage app); bool installApp(ApplicationPackage app);
/// Check if the device is currently connected
bool isConnected();
/// Check if the device is supported by Flutter /// Check if the device is supported by Flutter
bool isSupported(); bool isSupported();
......
...@@ -125,9 +125,6 @@ class IOSDevice extends Device { ...@@ -125,9 +125,6 @@ class IOSDevice extends Device {
return false; return false;
} }
@override
bool isConnected() => _getAttachedDeviceIDs().contains(id);
@override @override
bool isSupported() => true; bool isSupported() => true;
...@@ -235,9 +232,6 @@ class _IOSDeviceLogReader extends DeviceLogReader { ...@@ -235,9 +232,6 @@ class _IOSDeviceLogReader extends DeviceLogReader {
// TODO(devoncarew): Support [clear]. // TODO(devoncarew): Support [clear].
Future<int> logs({ bool clear: false, bool showPrefix: false }) async { Future<int> logs({ bool clear: false, bool showPrefix: false }) async {
if (!device.isConnected())
return 2;
return await runCommandAndStreamOutput( return await runCommandAndStreamOutput(
<String>[device.loggerPath], <String>[device.loggerPath],
prefix: showPrefix ? '[$name] ' : '', prefix: showPrefix ? '[$name] ' : '',
......
...@@ -229,9 +229,6 @@ class IOSSimulator extends Device { ...@@ -229,9 +229,6 @@ class IOSSimulator extends Device {
@override @override
bool installApp(ApplicationPackage app) { bool installApp(ApplicationPackage app) {
if (!isConnected())
return false;
try { try {
SimControl.instance.install(id, app.localPath); SimControl.instance.install(id, app.localPath);
return true; return true;
...@@ -240,8 +237,6 @@ class IOSSimulator extends Device { ...@@ -240,8 +237,6 @@ class IOSSimulator extends Device {
} }
} }
bool isConnected() => Platform.isMacOS;
@override @override
bool isSupported() { bool isSupported() {
if (!Platform.isMacOS) { if (!Platform.isMacOS) {
...@@ -419,9 +414,6 @@ class _IOSSimulatorLogReader extends DeviceLogReader { ...@@ -419,9 +414,6 @@ class _IOSSimulatorLogReader extends DeviceLogReader {
String get name => device.name; String get name => device.name;
Future<int> logs({ bool clear: false, bool showPrefix: false }) async { Future<int> logs({ bool clear: false, bool showPrefix: false }) async {
if (!device.isConnected())
return 2;
if (clear) if (clear)
device.clearLogs(); device.clearLogs();
......
...@@ -112,13 +112,8 @@ defineTests() { ...@@ -112,13 +112,8 @@ defineTests() {
MockDeviceStore mockDevices = command.devices; MockDeviceStore mockDevices = command.devices;
when(mockDevices.android.isConnected()).thenReturn(true);
when(mockDevices.android.stopApp(any)).thenReturn(true); when(mockDevices.android.stopApp(any)).thenReturn(true);
when(mockDevices.iOS.isConnected()).thenReturn(false);
when(mockDevices.iOS.stopApp(any)).thenReturn(false); when(mockDevices.iOS.stopApp(any)).thenReturn(false);
when(mockDevices.iOSSimulator.isConnected()).thenReturn(false);
when(mockDevices.iOSSimulator.stopApp(any)).thenReturn(false); when(mockDevices.iOSSimulator.stopApp(any)).thenReturn(false);
commands.add({'id': 0, 'method': 'app.stopAll'}); commands.add({'id': 0, 'method': 'app.stopAll'});
......
...@@ -19,15 +19,12 @@ defineTests() { ...@@ -19,15 +19,12 @@ defineTests() {
applyMocksToCommand(command); applyMocksToCommand(command);
MockDeviceStore mockDevices = command.devices; MockDeviceStore mockDevices = command.devices;
when(mockDevices.android.isConnected()).thenReturn(true);
when(mockDevices.android.isAppInstalled(any)).thenReturn(false); when(mockDevices.android.isAppInstalled(any)).thenReturn(false);
when(mockDevices.android.installApp(any)).thenReturn(true); when(mockDevices.android.installApp(any)).thenReturn(true);
when(mockDevices.iOS.isConnected()).thenReturn(false);
when(mockDevices.iOS.isAppInstalled(any)).thenReturn(false); when(mockDevices.iOS.isAppInstalled(any)).thenReturn(false);
when(mockDevices.iOS.installApp(any)).thenReturn(false); when(mockDevices.iOS.installApp(any)).thenReturn(false);
when(mockDevices.iOSSimulator.isConnected()).thenReturn(false);
when(mockDevices.iOSSimulator.isAppInstalled(any)).thenReturn(false); when(mockDevices.iOSSimulator.isAppInstalled(any)).thenReturn(false);
when(mockDevices.iOSSimulator.installApp(any)).thenReturn(false); when(mockDevices.iOSSimulator.installApp(any)).thenReturn(false);
...@@ -43,15 +40,12 @@ defineTests() { ...@@ -43,15 +40,12 @@ defineTests() {
applyMocksToCommand(command); applyMocksToCommand(command);
MockDeviceStore mockDevices = command.devices; MockDeviceStore mockDevices = command.devices;
when(mockDevices.android.isConnected()).thenReturn(false);
when(mockDevices.android.isAppInstalled(any)).thenReturn(false); when(mockDevices.android.isAppInstalled(any)).thenReturn(false);
when(mockDevices.android.installApp(any)).thenReturn(false); when(mockDevices.android.installApp(any)).thenReturn(false);
when(mockDevices.iOS.isConnected()).thenReturn(true);
when(mockDevices.iOS.isAppInstalled(any)).thenReturn(false); when(mockDevices.iOS.isAppInstalled(any)).thenReturn(false);
when(mockDevices.iOS.installApp(any)).thenReturn(true); when(mockDevices.iOS.installApp(any)).thenReturn(true);
when(mockDevices.iOSSimulator.isConnected()).thenReturn(false);
when(mockDevices.iOSSimulator.isAppInstalled(any)).thenReturn(false); when(mockDevices.iOSSimulator.isAppInstalled(any)).thenReturn(false);
when(mockDevices.iOSSimulator.installApp(any)).thenReturn(false); when(mockDevices.iOSSimulator.installApp(any)).thenReturn(false);
......
...@@ -48,8 +48,11 @@ void testUsingContext(String description, dynamic testMethod(), { ...@@ -48,8 +48,11 @@ void testUsingContext(String description, dynamic testMethod(), {
if (!overrides.containsKey(OperatingSystemUtils)) if (!overrides.containsKey(OperatingSystemUtils))
testContext[OperatingSystemUtils] = new MockOperatingSystemUtils(); testContext[OperatingSystemUtils] = new MockOperatingSystemUtils();
if (!overrides.containsKey(IOSSimulatorUtils)) if (!overrides.containsKey(IOSSimulatorUtils)) {
testContext[IOSSimulatorUtils] = new MockIOSSimulatorUtils(); MockIOSSimulatorUtils mock = new MockIOSSimulatorUtils();
when(mock.getAttachedDevices()).thenReturn(<IOSSimulator>[]);
testContext[IOSSimulatorUtils] = mock;
}
if (Platform.isMacOS) { if (Platform.isMacOS) {
if (!overrides.containsKey(XCode)) if (!overrides.containsKey(XCode))
......
...@@ -19,13 +19,8 @@ defineTests() { ...@@ -19,13 +19,8 @@ defineTests() {
applyMocksToCommand(command); applyMocksToCommand(command);
MockDeviceStore mockDevices = command.devices; MockDeviceStore mockDevices = command.devices;
when(mockDevices.android.isConnected()).thenReturn(true);
when(mockDevices.android.stopApp(any)).thenReturn(true); when(mockDevices.android.stopApp(any)).thenReturn(true);
when(mockDevices.iOS.isConnected()).thenReturn(false);
when(mockDevices.iOS.stopApp(any)).thenReturn(false); when(mockDevices.iOS.stopApp(any)).thenReturn(false);
when(mockDevices.iOSSimulator.isConnected()).thenReturn(false);
when(mockDevices.iOSSimulator.stopApp(any)).thenReturn(false); when(mockDevices.iOSSimulator.stopApp(any)).thenReturn(false);
return createTestCommandRunner(command).run(['stop']).then((int code) { return createTestCommandRunner(command).run(['stop']).then((int code) {
...@@ -38,13 +33,8 @@ defineTests() { ...@@ -38,13 +33,8 @@ defineTests() {
applyMocksToCommand(command); applyMocksToCommand(command);
MockDeviceStore mockDevices = command.devices; MockDeviceStore mockDevices = command.devices;
when(mockDevices.android.isConnected()).thenReturn(false);
when(mockDevices.android.stopApp(any)).thenReturn(false); when(mockDevices.android.stopApp(any)).thenReturn(false);
when(mockDevices.iOS.isConnected()).thenReturn(true);
when(mockDevices.iOS.stopApp(any)).thenReturn(true); when(mockDevices.iOS.stopApp(any)).thenReturn(true);
when(mockDevices.iOSSimulator.isConnected()).thenReturn(false);
when(mockDevices.iOSSimulator.stopApp(any)).thenReturn(false); when(mockDevices.iOSSimulator.stopApp(any)).thenReturn(false);
return createTestCommandRunner(command).run(['stop']).then((int code) { return createTestCommandRunner(command).run(['stop']).then((int code) {
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
// found in the LICENSE file. // found in the LICENSE file.
import 'package:flutter_tools/src/commands/trace.dart'; import 'package:flutter_tools/src/commands/trace.dart';
import 'package:mockito/mockito.dart';
import 'package:test/test.dart'; import 'package:test/test.dart';
import 'src/common.dart'; import 'src/common.dart';
...@@ -17,10 +16,6 @@ defineTests() { ...@@ -17,10 +16,6 @@ defineTests() {
testUsingContext('returns 1 when no Android device is connected', () { testUsingContext('returns 1 when no Android device is connected', () {
TraceCommand command = new TraceCommand(); TraceCommand command = new TraceCommand();
applyMocksToCommand(command); applyMocksToCommand(command);
MockDeviceStore mockDevices = command.devices;
when(mockDevices.android.isConnected()).thenReturn(false);
return createTestCommandRunner(command).run(['trace']).then((int code) { return createTestCommandRunner(command).run(['trace']).then((int code) {
expect(code, equals(1)); expect(code, equals(1));
}); });
......
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