Commit 022047f5 authored by Devon Carew's avatar Devon Carew

remove the isConnected() method from device

parent 240e499b
......@@ -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<String> adbCommandForDevice(List<String> args) {
......@@ -152,9 +146,6 @@ class AndroidDevice extends Device {
@override
bool isAppInstalled(ApplicationPackage app) {
if (!isConnected())
return false;
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...');
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<bool> refreshSnapshot(AndroidApk apk, String snapshotPath) async {
if (!FileSystemEntity.isFileSync(snapshotPath)) {
printError('Cannot find $snapshotPath');
......@@ -462,13 +442,12 @@ List<AndroidDevice> 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<int> logs({ bool clear: false, bool showPrefix: false }) async {
if (!device.isConnected())
return 2;
if (clear)
device.clearLogs();
......
......@@ -430,7 +430,7 @@ Future<int> 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.
......
......@@ -347,7 +347,7 @@ Map<String, dynamic> _deviceToMap(Device device) {
'id': device.id,
'name': device.name,
'platform': _enumToString(device.platform),
'available': device.isConnected()
'available': true
};
}
......
......@@ -30,7 +30,7 @@ Future<bool> 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;
......
......@@ -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;
}
......
......@@ -185,7 +185,7 @@ Future<int> 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<int> 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);
}
......
......@@ -26,7 +26,7 @@ Future<bool> 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;
......
......@@ -33,7 +33,7 @@ class TraceCommand extends FlutterCommand {
Future<int> 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;
}
......
......@@ -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();
......
......@@ -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<int> logs({ bool clear: false, bool showPrefix: false }) async {
if (!device.isConnected())
return 2;
return await runCommandAndStreamOutput(
<String>[device.loggerPath],
prefix: showPrefix ? '[$name] ' : '',
......
......@@ -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<int> logs({ bool clear: false, bool showPrefix: false }) async {
if (!device.isConnected())
return 2;
if (clear)
device.clearLogs();
......
......@@ -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'});
......
......@@ -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);
......
......@@ -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(<IOSSimulator>[]);
testContext[IOSSimulatorUtils] = mock;
}
if (Platform.isMacOS) {
if (!overrides.containsKey(XCode))
......
......@@ -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) {
......
......@@ -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));
});
......
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