remove the isConnected() method from device

This commit is contained in:
Devon Carew
2016-02-26 13:23:48 -08:00
parent 240e499bc0
commit 022047f5eb
16 changed files with 19 additions and 82 deletions

View File

@@ -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();

View File

@@ -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.

View File

@@ -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
};
}

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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);
}

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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();

View File

@@ -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] ' : '',

View File

@@ -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();