OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library android; | 5 library android; |
6 | 6 |
7 import "dart:async"; | 7 import "dart:async"; |
8 import "dart:convert" show LineSplitter, UTF8; | 8 import "dart:convert" show LineSplitter, UTF8; |
9 import "dart:core"; | 9 import "dart:core"; |
10 import "dart:collection"; | 10 import "dart:collection"; |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 }); | 138 }); |
139 getLines(_emulatorProcess.stderr).listen((line) { | 139 getLines(_emulatorProcess.stderr).listen((line) { |
140 log("stderr: ${line.trim()}"); | 140 log("stderr: ${line.trim()}"); |
141 }); | 141 }); |
142 _emulatorProcess.exitCode.then((exitCode) { | 142 _emulatorProcess.exitCode.then((exitCode) { |
143 log("emulator exited with exitCode: $exitCode."); | 143 log("emulator exited with exitCode: $exitCode."); |
144 }); | 144 }); |
145 } | 145 } |
146 | 146 |
147 Future<bool> kill() { | 147 Future<bool> kill() { |
148 var completer = new Completer(); | 148 var completer = new Completer<bool>(); |
149 if (_emulatorProcess.kill()) { | 149 if (_emulatorProcess.kill()) { |
150 _emulatorProcess.exitCode.then((exitCode) { | 150 _emulatorProcess.exitCode.then((exitCode) { |
151 // TODO: Should we use exitCode to do something clever? | 151 // TODO: Should we use exitCode to do something clever? |
152 completer.complete(true); | 152 completer.complete(true); |
153 }); | 153 }); |
154 } else { | 154 } else { |
155 log("Sending kill signal to emulator process failed"); | 155 log("Sending kill signal to emulator process failed"); |
156 completer.complete(false); | 156 completer.complete(false); |
157 } | 157 } |
158 return completer.future; | 158 return completer.future; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 * Blocks execution until the device is online | 202 * Blocks execution until the device is online |
203 */ | 203 */ |
204 Future waitForDevice() { | 204 Future waitForDevice() { |
205 return _adbCommand(['wait-for-device']); | 205 return _adbCommand(['wait-for-device']); |
206 } | 206 } |
207 | 207 |
208 /** | 208 /** |
209 * Polls the 'sys.boot_completed' property. Returns as soon as the property is | 209 * Polls the 'sys.boot_completed' property. Returns as soon as the property is |
210 * 1. | 210 * 1. |
211 */ | 211 */ |
212 Future waitForBootCompleted() async { | 212 Future<Null> waitForBootCompleted() async { |
213 while (true) { | 213 while (true) { |
214 try { | 214 try { |
215 AdbCommandResult result = | 215 AdbCommandResult result = |
216 await _adbCommand(['shell', 'getprop', 'sys.boot_completed']); | 216 await _adbCommand(['shell', 'getprop', 'sys.boot_completed']); |
217 if (result.stdout.trim() == '1') return; | 217 if (result.stdout.trim() == '1') return; |
218 } catch (_) {} | 218 } catch (_) {} |
219 await new Future.delayed(const Duration(seconds: 2)); | 219 await new Future<Null>.delayed(const Duration(seconds: 2)); |
220 } | 220 } |
221 } | 221 } |
222 | 222 |
223 /** | 223 /** |
224 * Put adb in root mode. | 224 * Put adb in root mode. |
225 */ | 225 */ |
226 Future adbRoot() { | 226 Future<bool> adbRoot() { |
227 var adbRootCompleter = new Completer(); | 227 var adbRootCompleter = new Completer<bool>(); |
228 _adbCommand(['root']).then((_) { | 228 _adbCommand(['root']).then((_) { |
229 // TODO: Figure out a way to wait until the adb daemon was restarted in | 229 // TODO: Figure out a way to wait until the adb daemon was restarted in |
230 // 'root mode' on the device. | 230 // 'root mode' on the device. |
231 new Timer(_adbServerStartupTime, () => adbRootCompleter.complete(true)); | 231 new Timer(_adbServerStartupTime, () => adbRootCompleter.complete(true)); |
232 }).catchError((error) => adbRootCompleter.completeError(error)); | 232 }).catchError((error) => adbRootCompleter.completeError(error)); |
233 return adbRootCompleter.future; | 233 return adbRootCompleter.future; |
234 } | 234 } |
235 | 235 |
236 /** | 236 /** |
237 * Download data form the device. | 237 * Download data form the device. |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 'Please make sure "adb devices" shows your device!'); | 428 'Please make sure "adb devices" shows your device!'); |
429 } | 429 } |
430 print("Found ${devices.length} Android devices."); | 430 print("Found ${devices.length} Android devices."); |
431 return new AdbDevicePool(devices); | 431 return new AdbDevicePool(devices); |
432 } | 432 } |
433 | 433 |
434 Future<AdbDevice> acquireDevice() async { | 434 Future<AdbDevice> acquireDevice() async { |
435 if (_idleDevices.length > 0) { | 435 if (_idleDevices.length > 0) { |
436 return _idleDevices.removeFirst(); | 436 return _idleDevices.removeFirst(); |
437 } else { | 437 } else { |
438 var completer = new Completer(); | 438 var completer = new Completer<AdbDevice>(); |
439 _waiter.add(completer); | 439 _waiter.add(completer); |
440 return completer.future; | 440 return completer.future; |
441 } | 441 } |
442 } | 442 } |
443 | 443 |
444 void releaseDevice(AdbDevice device) { | 444 void releaseDevice(AdbDevice device) { |
445 if (_waiter.length > 0) { | 445 if (_waiter.length > 0) { |
446 Completer completer = _waiter.removeFirst(); | 446 Completer completer = _waiter.removeFirst(); |
447 completer.complete(device); | 447 completer.complete(device); |
448 } else { | 448 } else { |
449 _idleDevices.add(device); | 449 _idleDevices.add(device); |
450 } | 450 } |
451 } | 451 } |
452 } | 452 } |
OLD | NEW |