Commit 8bb8e1d9 authored by Devon Carew's avatar Devon Carew

add device notifications to the daemon command

parent 477530f3
......@@ -21,8 +21,14 @@ abstract class Device {
return _deviceCache.putIfAbsent(id, () => constructor(id));
}
static void removeFromCache(String id) {
_deviceCache.remove(id);
}
Device._(this.id);
String get name;
/// Install an app package on the current device
bool installApp(ApplicationPackage app);
......@@ -532,20 +538,25 @@ class AndroidDevice extends Device {
String modelID;
String deviceCodeName;
bool _connected;
String _adbPath;
String get adbPath => _adbPath;
bool _hasAdb = false;
bool _hasValidAndroid = false;
factory AndroidDevice(
{String id: null,
String productID: null,
String modelID: null,
String deviceCodeName: null}) {
factory AndroidDevice({
String id: null,
String productID: null,
String modelID: null,
String deviceCodeName: null,
bool connected
}) {
AndroidDevice device = Device._unique(id ?? defaultDeviceID, (String id) => new AndroidDevice._(id));
device.productID = productID;
device.modelID = modelID;
device.deviceCodeName = deviceCodeName;
if (connected != null)
device._connected = connected;
return device;
}
......@@ -553,7 +564,7 @@ class AndroidDevice extends Device {
/// we don't have to rely on the test setup having adb available to it.
static List<AndroidDevice> getAttachedDevices([AndroidDevice mockAndroid]) {
List<AndroidDevice> devices = [];
String adbPath = (mockAndroid != null) ? mockAndroid.adbPath : _getAdbPath();
String adbPath = (mockAndroid != null) ? mockAndroid.adbPath : getAdbPath();
try {
runCheckedSync([adbPath, 'version']);
......@@ -623,7 +634,7 @@ class AndroidDevice extends Device {
}
AndroidDevice._(id) : super._(id) {
_adbPath = _getAdbPath();
_adbPath = getAdbPath();
_hasAdb = _checkForAdb();
// Checking for [minApiName] only needs to be done if we are starting an
......@@ -655,7 +666,7 @@ class AndroidDevice extends Device {
}
}
static String _getAdbPath() {
static String getAdbPath() {
if (Platform.environment.containsKey('ANDROID_HOME')) {
String androidHomeDir = Platform.environment['ANDROID_HOME'];
String adbPath1 = path.join(androidHomeDir, 'sdk', 'platform-tools', 'adb');
......@@ -782,6 +793,8 @@ class AndroidDevice extends Device {
return CryptoUtils.bytesToHex(sha1.close());
}
String get name => modelID;
@override
bool isAppInstalled(ApplicationPackage app) {
if (!isConnected()) {
......@@ -992,8 +1005,11 @@ class AndroidDevice extends Device {
return null;
}
@override
bool isConnected() => _hasValidAndroid;
bool isConnected() => _connected != null ? _connected : _hasValidAndroid;
void setConnected(bool value) {
_connected = value;
}
}
class DeviceStore {
......
......@@ -26,9 +26,9 @@ defineTests() {
StreamController<Map> responses = new StreamController();
daemon = new Daemon(
commands.stream,
(Map result) => responses.add(result)
(Map<String, dynamic> result) => responses.add(result)
);
commands.add({'id': 0, 'event': 'daemon.version'});
commands.add({'id': 0, 'method': 'daemon.version'});
Map response = await responses.stream.first;
expect(response['id'], 0);
expect(response['result'], isNotEmpty);
......@@ -40,9 +40,9 @@ defineTests() {
StreamController<Map> responses = new StreamController();
daemon = new Daemon(
commands.stream,
(Map result) => responses.add(result)
(Map<String, dynamic> result) => responses.add(result)
);
commands.add({'id': 0, 'event': 'daemon.shutdown'});
commands.add({'id': 0, 'method': 'daemon.shutdown'});
return daemon.onExit.then((int code) {
expect(code, 0);
});
......@@ -56,7 +56,7 @@ defineTests() {
StreamController<Map> responses = new StreamController();
daemon = new Daemon(
commands.stream,
(Map result) => responses.add(result),
(Map<String, dynamic> result) => responses.add(result),
daemonCommand: command
);
......@@ -71,10 +71,23 @@ defineTests() {
when(mockDevices.iOSSimulator.isConnected()).thenReturn(false);
when(mockDevices.iOSSimulator.stopApp(any)).thenReturn(false);
commands.add({'id': 0, 'event': 'app.stopAll'});
commands.add({'id': 0, 'method': 'app.stopAll'});
Map response = await responses.stream.first;
expect(response['id'], 0);
expect(response['result'], true);
});
test('device.getDevices', () async {
StreamController<Map> commands = new StreamController();
StreamController<Map> responses = new StreamController();
daemon = new Daemon(
commands.stream,
(Map<String, dynamic> result) => responses.add(result)
);
commands.add({'id': 0, 'method': 'device.getDevices'});
Map response = await responses.stream.first;
expect(response['id'], 0);
expect(response['result'], isList);
});
});
}
......@@ -7,8 +7,15 @@ import 'dart:io';
Process daemon;
// To use, start from the console and enter:
// version: print version
// shutdown: terminate the server
// start: start an app
// stopAll: stop any running app
// devices: list devices
main() async {
daemon = await Process.start('dart', ['bin/flutter_tools.dart', 'daemon']);
daemon = await Process.start('flutter', ['daemon']);
print('daemon process started, pid: ${daemon.pid}');
daemon.stdout
......@@ -20,13 +27,15 @@ main() async {
stdout.write('> ');
stdin.transform(UTF8.decoder).transform(const LineSplitter()).listen((String line) {
if (line == 'version' || line == 'v') {
_send({'event': 'daemon.version'});
_send({'method': 'daemon.version'});
} else if (line == 'shutdown' || line == 'q') {
_send({'event': 'daemon.shutdown'});
_send({'method': 'daemon.shutdown'});
} else if (line == 'start') {
_send({'event': 'app.start'});
_send({'method': 'app.start'});
} else if (line == 'stopAll') {
_send({'event': 'app.stopAll'});
_send({'method': 'app.stopAll'});
} else if (line == 'devices') {
_send({'method': 'device.getDevices'});
} else {
print('command not understood: ${line}');
}
......
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