From 022047f5eb8ee017ca167b1c17704f06cb298998 Mon Sep 17 00:00:00 2001 From: Devon Carew Date: Fri, 26 Feb 2016 13:23:48 -0800 Subject: [PATCH] remove the isConnected() method from device --- .../lib/src/android/android_device.dart | 32 +++---------------- .../flutter_tools/lib/src/commands/apk.dart | 2 +- .../lib/src/commands/daemon.dart | 2 +- .../lib/src/commands/install.dart | 2 +- .../lib/src/commands/refresh.dart | 2 +- .../flutter_tools/lib/src/commands/run.dart | 7 ++-- .../flutter_tools/lib/src/commands/stop.dart | 2 +- .../flutter_tools/lib/src/commands/trace.dart | 2 +- packages/flutter_tools/lib/src/device.dart | 3 -- .../flutter_tools/lib/src/ios/devices.dart | 6 ---- .../flutter_tools/lib/src/ios/simulators.dart | 8 ----- packages/flutter_tools/test/daemon_test.dart | 5 --- packages/flutter_tools/test/install_test.dart | 6 ---- packages/flutter_tools/test/src/context.dart | 7 ++-- packages/flutter_tools/test/stop_test.dart | 10 ------ packages/flutter_tools/test/trace_test.dart | 5 --- 16 files changed, 19 insertions(+), 82 deletions(-) diff --git a/packages/flutter_tools/lib/src/android/android_device.dart b/packages/flutter_tools/lib/src/android/android_device.dart index fbd61383987..aa09f7a9a81 100644 --- a/packages/flutter_tools/lib/src/android/android_device.dart +++ b/packages/flutter_tools/lib/src/android/android_device.dart @@ -41,19 +41,13 @@ class AndroidDevice extends Device { String id, { this.productID, this.modelID, - this.deviceCodeName, - bool connected - }) : super(id) { - if (connected != null) - _connected = connected; - } + this.deviceCodeName + }) : super(id); final String productID; final String modelID; final String deviceCodeName; - bool _connected; - bool get isLocalEmulator => false; List adbCommandForDevice(List args) { @@ -152,9 +146,6 @@ class AndroidDevice extends Device { @override bool isAppInstalled(ApplicationPackage app) { - if (!isConnected()) - return false; - if (runCheckedSync(adbCommandForDevice(['shell', 'pm', 'path', app.id])) == '') { printTrace('TODO(iansf): move this log to the caller. ${app.name} is not on the device. Installing now...'); return false; @@ -169,11 +160,6 @@ class AndroidDevice extends Device { @override bool installApp(ApplicationPackage app) { - if (!isConnected()) { - printTrace('Android device not connected. Not installing.'); - return false; - } - if (!FileSystemEntity.isFileSync(app.localPath)) { printError('"${app.localPath}" does not exist.'); return false; @@ -390,14 +376,8 @@ class AndroidDevice extends Device { return null; } - bool isConnected() => _connected ?? androidSdk != null; - bool isSupported() => true; - void setConnected(bool value) { - _connected = value; - } - Future refreshSnapshot(AndroidApk apk, String snapshotPath) async { if (!FileSystemEntity.isFileSync(snapshotPath)) { printError('Cannot find $snapshotPath'); @@ -462,13 +442,12 @@ List getAdbDevices() { deviceID, productID: productID, modelID: modelID, - deviceCodeName: deviceCodeName, - connected: true + deviceCodeName: deviceCodeName )); } else if (deviceRegex2.hasMatch(line)) { Match match = deviceRegex2.firstMatch(line); String deviceID = match[1]; - devices.add(new AndroidDevice(deviceID, connected: true)); + devices.add(new AndroidDevice(deviceID)); } else if (unauthorizedRegex.hasMatch(line)) { Match match = unauthorizedRegex.firstMatch(line); String deviceID = match[1]; @@ -499,9 +478,6 @@ class _AdbLogReader extends DeviceLogReader { String get name => device.name; Future logs({ bool clear: false, bool showPrefix: false }) async { - if (!device.isConnected()) - return 2; - if (clear) device.clearLogs(); diff --git a/packages/flutter_tools/lib/src/commands/apk.dart b/packages/flutter_tools/lib/src/commands/apk.dart index bd60d36803a..fb3ee01a28f 100644 --- a/packages/flutter_tools/lib/src/commands/apk.dart +++ b/packages/flutter_tools/lib/src/commands/apk.dart @@ -430,7 +430,7 @@ Future buildAll( }) async { for (Device device in devices.all) { ApplicationPackage package = applicationPackages.getPackageForPlatform(device.platform); - if (package == null || !device.isConnected()) + if (package == null) continue; // TODO(mpcomplete): Temporary hack. We only support the apk builder atm. diff --git a/packages/flutter_tools/lib/src/commands/daemon.dart b/packages/flutter_tools/lib/src/commands/daemon.dart index beea6cba470..577a044644b 100644 --- a/packages/flutter_tools/lib/src/commands/daemon.dart +++ b/packages/flutter_tools/lib/src/commands/daemon.dart @@ -347,7 +347,7 @@ Map _deviceToMap(Device device) { 'id': device.id, 'name': device.name, 'platform': _enumToString(device.platform), - 'available': device.isConnected() + 'available': true }; } diff --git a/packages/flutter_tools/lib/src/commands/install.dart b/packages/flutter_tools/lib/src/commands/install.dart index e0f38a7a6eb..e82b8fbc96e 100644 --- a/packages/flutter_tools/lib/src/commands/install.dart +++ b/packages/flutter_tools/lib/src/commands/install.dart @@ -30,7 +30,7 @@ Future installApp( for (Device device in devices.all) { ApplicationPackage package = applicationPackages.getPackageForPlatform(device.platform); - if (package == null || !device.isConnected() || device.isAppInstalled(package)) + if (package == null || device.isAppInstalled(package)) continue; if (device.installApp(package)) installedSomewhere = true; diff --git a/packages/flutter_tools/lib/src/commands/refresh.dart b/packages/flutter_tools/lib/src/commands/refresh.dart index 92b0af71b9d..a3c5cf7c60b 100644 --- a/packages/flutter_tools/lib/src/commands/refresh.dart +++ b/packages/flutter_tools/lib/src/commands/refresh.dart @@ -36,7 +36,7 @@ class RefreshCommand extends FlutterCommand { downloadApplicationPackagesAndConnectToDevices(), ], eagerError: true); - if (devices.android == null || !devices.android.isConnected()) { + if (devices.android == null) { printError('No device connected.'); return 1; } diff --git a/packages/flutter_tools/lib/src/commands/run.dart b/packages/flutter_tools/lib/src/commands/run.dart index 5e29baa2e99..55d8bee5e43 100644 --- a/packages/flutter_tools/lib/src/commands/run.dart +++ b/packages/flutter_tools/lib/src/commands/run.dart @@ -185,7 +185,7 @@ Future startApp( for (Device device in devices.all) { ApplicationPackage package = applicationPackages.getPackageForPlatform(device.platform); - if (package == null || !device.isConnected()) + if (package == null) continue; if (!device.isSupported()) { @@ -230,13 +230,14 @@ Future startApp( } if (!startedSomething) { - int connected = devices.all.where((device) => device.isConnected()).length; String message = 'Unable to run application'; - if (connected == 0) { + + if (devices.all.isEmpty) { message += ' - no connected devices.'; } else if (unsupportedCount != 0) { message += ' - $unsupportedCount unsupported ${pluralize('device', unsupportedCount)} connected'; } + printError(message); } diff --git a/packages/flutter_tools/lib/src/commands/stop.dart b/packages/flutter_tools/lib/src/commands/stop.dart index 8f9447243e9..e463ee9e69f 100644 --- a/packages/flutter_tools/lib/src/commands/stop.dart +++ b/packages/flutter_tools/lib/src/commands/stop.dart @@ -26,7 +26,7 @@ Future stopAll(DeviceStore devices, ApplicationPackageStore applicationPac for (Device device in devices.all) { ApplicationPackage package = applicationPackages.getPackageForPlatform(device.platform); - if (package == null || !device.isConnected()) + if (package == null) continue; if (await device.stopApp(package)) stoppedSomething = true; diff --git a/packages/flutter_tools/lib/src/commands/trace.dart b/packages/flutter_tools/lib/src/commands/trace.dart index 7e5953ef419..1676844a987 100644 --- a/packages/flutter_tools/lib/src/commands/trace.dart +++ b/packages/flutter_tools/lib/src/commands/trace.dart @@ -33,7 +33,7 @@ class TraceCommand extends FlutterCommand { Future runInProject() async { await downloadApplicationPackagesAndConnectToDevices(); - if (devices.android == null || !devices.android.isConnected()) { + if (devices.android == null) { printError('No device connected, so no trace was completed.'); return 1; } diff --git a/packages/flutter_tools/lib/src/device.dart b/packages/flutter_tools/lib/src/device.dart index 520ddd2020e..985bc6b1600 100644 --- a/packages/flutter_tools/lib/src/device.dart +++ b/packages/flutter_tools/lib/src/device.dart @@ -136,9 +136,6 @@ abstract class Device { /// Install an app package on the current device bool installApp(ApplicationPackage app); - /// Check if the device is currently connected - bool isConnected(); - /// Check if the device is supported by Flutter bool isSupported(); diff --git a/packages/flutter_tools/lib/src/ios/devices.dart b/packages/flutter_tools/lib/src/ios/devices.dart index e03169b53f4..3f57bd25b28 100644 --- a/packages/flutter_tools/lib/src/ios/devices.dart +++ b/packages/flutter_tools/lib/src/ios/devices.dart @@ -125,9 +125,6 @@ class IOSDevice extends Device { return false; } - @override - bool isConnected() => _getAttachedDeviceIDs().contains(id); - @override bool isSupported() => true; @@ -235,9 +232,6 @@ class _IOSDeviceLogReader extends DeviceLogReader { // TODO(devoncarew): Support [clear]. Future logs({ bool clear: false, bool showPrefix: false }) async { - if (!device.isConnected()) - return 2; - return await runCommandAndStreamOutput( [device.loggerPath], prefix: showPrefix ? '[$name] ' : '', diff --git a/packages/flutter_tools/lib/src/ios/simulators.dart b/packages/flutter_tools/lib/src/ios/simulators.dart index a908bd616b0..2ee184665d0 100644 --- a/packages/flutter_tools/lib/src/ios/simulators.dart +++ b/packages/flutter_tools/lib/src/ios/simulators.dart @@ -229,9 +229,6 @@ class IOSSimulator extends Device { @override bool installApp(ApplicationPackage app) { - if (!isConnected()) - return false; - try { SimControl.instance.install(id, app.localPath); return true; @@ -240,8 +237,6 @@ class IOSSimulator extends Device { } } - bool isConnected() => Platform.isMacOS; - @override bool isSupported() { if (!Platform.isMacOS) { @@ -419,9 +414,6 @@ class _IOSSimulatorLogReader extends DeviceLogReader { String get name => device.name; Future logs({ bool clear: false, bool showPrefix: false }) async { - if (!device.isConnected()) - return 2; - if (clear) device.clearLogs(); diff --git a/packages/flutter_tools/test/daemon_test.dart b/packages/flutter_tools/test/daemon_test.dart index 5682dcd5064..5df8a089ae5 100644 --- a/packages/flutter_tools/test/daemon_test.dart +++ b/packages/flutter_tools/test/daemon_test.dart @@ -112,13 +112,8 @@ defineTests() { MockDeviceStore mockDevices = command.devices; - when(mockDevices.android.isConnected()).thenReturn(true); when(mockDevices.android.stopApp(any)).thenReturn(true); - - when(mockDevices.iOS.isConnected()).thenReturn(false); when(mockDevices.iOS.stopApp(any)).thenReturn(false); - - when(mockDevices.iOSSimulator.isConnected()).thenReturn(false); when(mockDevices.iOSSimulator.stopApp(any)).thenReturn(false); commands.add({'id': 0, 'method': 'app.stopAll'}); diff --git a/packages/flutter_tools/test/install_test.dart b/packages/flutter_tools/test/install_test.dart index c3e8546f2b6..fc7d2fd313b 100644 --- a/packages/flutter_tools/test/install_test.dart +++ b/packages/flutter_tools/test/install_test.dart @@ -19,15 +19,12 @@ defineTests() { applyMocksToCommand(command); MockDeviceStore mockDevices = command.devices; - when(mockDevices.android.isConnected()).thenReturn(true); when(mockDevices.android.isAppInstalled(any)).thenReturn(false); when(mockDevices.android.installApp(any)).thenReturn(true); - when(mockDevices.iOS.isConnected()).thenReturn(false); when(mockDevices.iOS.isAppInstalled(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.installApp(any)).thenReturn(false); @@ -43,15 +40,12 @@ defineTests() { applyMocksToCommand(command); MockDeviceStore mockDevices = command.devices; - when(mockDevices.android.isConnected()).thenReturn(false); when(mockDevices.android.isAppInstalled(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.installApp(any)).thenReturn(true); - when(mockDevices.iOSSimulator.isConnected()).thenReturn(false); when(mockDevices.iOSSimulator.isAppInstalled(any)).thenReturn(false); when(mockDevices.iOSSimulator.installApp(any)).thenReturn(false); diff --git a/packages/flutter_tools/test/src/context.dart b/packages/flutter_tools/test/src/context.dart index 4fb8fb234e7..3683b10e7ca 100644 --- a/packages/flutter_tools/test/src/context.dart +++ b/packages/flutter_tools/test/src/context.dart @@ -48,8 +48,11 @@ void testUsingContext(String description, dynamic testMethod(), { if (!overrides.containsKey(OperatingSystemUtils)) testContext[OperatingSystemUtils] = new MockOperatingSystemUtils(); - if (!overrides.containsKey(IOSSimulatorUtils)) - testContext[IOSSimulatorUtils] = new MockIOSSimulatorUtils(); + if (!overrides.containsKey(IOSSimulatorUtils)) { + MockIOSSimulatorUtils mock = new MockIOSSimulatorUtils(); + when(mock.getAttachedDevices()).thenReturn([]); + testContext[IOSSimulatorUtils] = mock; + } if (Platform.isMacOS) { if (!overrides.containsKey(XCode)) diff --git a/packages/flutter_tools/test/stop_test.dart b/packages/flutter_tools/test/stop_test.dart index 0c0c08e1c48..82b733e1824 100644 --- a/packages/flutter_tools/test/stop_test.dart +++ b/packages/flutter_tools/test/stop_test.dart @@ -19,13 +19,8 @@ defineTests() { applyMocksToCommand(command); MockDeviceStore mockDevices = command.devices; - when(mockDevices.android.isConnected()).thenReturn(true); when(mockDevices.android.stopApp(any)).thenReturn(true); - - when(mockDevices.iOS.isConnected()).thenReturn(false); when(mockDevices.iOS.stopApp(any)).thenReturn(false); - - when(mockDevices.iOSSimulator.isConnected()).thenReturn(false); when(mockDevices.iOSSimulator.stopApp(any)).thenReturn(false); return createTestCommandRunner(command).run(['stop']).then((int code) { @@ -38,13 +33,8 @@ defineTests() { applyMocksToCommand(command); MockDeviceStore mockDevices = command.devices; - when(mockDevices.android.isConnected()).thenReturn(false); when(mockDevices.android.stopApp(any)).thenReturn(false); - - when(mockDevices.iOS.isConnected()).thenReturn(true); when(mockDevices.iOS.stopApp(any)).thenReturn(true); - - when(mockDevices.iOSSimulator.isConnected()).thenReturn(false); when(mockDevices.iOSSimulator.stopApp(any)).thenReturn(false); return createTestCommandRunner(command).run(['stop']).then((int code) { diff --git a/packages/flutter_tools/test/trace_test.dart b/packages/flutter_tools/test/trace_test.dart index 444da3ec604..5fc2cd75f64 100644 --- a/packages/flutter_tools/test/trace_test.dart +++ b/packages/flutter_tools/test/trace_test.dart @@ -3,7 +3,6 @@ // found in the LICENSE file. import 'package:flutter_tools/src/commands/trace.dart'; -import 'package:mockito/mockito.dart'; import 'package:test/test.dart'; import 'src/common.dart'; @@ -17,10 +16,6 @@ defineTests() { testUsingContext('returns 1 when no Android device is connected', () { TraceCommand command = new TraceCommand(); applyMocksToCommand(command); - MockDeviceStore mockDevices = command.devices; - - when(mockDevices.android.isConnected()).thenReturn(false); - return createTestCommandRunner(command).run(['trace']).then((int code) { expect(code, equals(1)); });