| 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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 result.throwIfFailed(); | 186 result.throwIfFailed(); |
| 187 } | 187 } |
| 188 } | 188 } |
| 189 | 189 |
| 190 /** | 190 /** |
| 191 * Used for communicating with an emulator or with a real device. | 191 * Used for communicating with an emulator or with a real device. |
| 192 */ | 192 */ |
| 193 class AdbDevice { | 193 class AdbDevice { |
| 194 static const _adbServerStartupTime = const Duration(seconds: 3); | 194 static const _adbServerStartupTime = const Duration(seconds: 3); |
| 195 String _deviceId; | 195 String _deviceId; |
| 196 Map<String, String> _cachedData = new Map<String, String>(); |
| 196 | 197 |
| 197 String get deviceId => _deviceId; | 198 String get deviceId => _deviceId; |
| 198 | 199 |
| 199 AdbDevice(this._deviceId); | 200 AdbDevice(this._deviceId); |
| 200 | 201 |
| 201 /** | 202 /** |
| 202 * Blocks execution until the device is online | 203 * Blocks execution until the device is online |
| 203 */ | 204 */ |
| 204 Future waitForDevice() { | 205 Future waitForDevice() { |
| 205 return _adbCommand(['wait-for-device']); | 206 return _adbCommand(['wait-for-device']); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 } | 242 } |
| 242 | 243 |
| 243 /** | 244 /** |
| 244 * Upload data to the device. | 245 * Upload data to the device. |
| 245 */ | 246 */ |
| 246 Future pushData(Path local, Path remote) { | 247 Future pushData(Path local, Path remote) { |
| 247 return _adbCommand(['push', '$local', '$remote']); | 248 return _adbCommand(['push', '$local', '$remote']); |
| 248 } | 249 } |
| 249 | 250 |
| 250 /** | 251 /** |
| 252 * Upload data to the device, unless [local] is the same as the most recently |
| 253 * used source for [remote]. |
| 254 */ |
| 255 Future pushCachedData(String local, String remote) { |
| 256 if (_cachedData[remote] == local) { |
| 257 return new Future.value(new AdbCommandResult( |
| 258 "Skipped cached push", "", "", 0, false)); |
| 259 } |
| 260 _cachedData[remote] = local; |
| 261 return _adbCommand(['push', local, remote]); |
| 262 } |
| 263 |
| 264 /** |
| 251 * Change permission of directory recursively. | 265 * Change permission of directory recursively. |
| 252 */ | 266 */ |
| 253 Future chmod(String mode, Path directory) { | 267 Future chmod(String mode, Path directory) { |
| 254 var arguments = ['shell', 'chmod', '-R', mode, '$directory']; | 268 var arguments = ['shell', 'chmod', '-R', mode, '$directory']; |
| 255 return _adbCommand(arguments); | 269 return _adbCommand(arguments); |
| 256 } | 270 } |
| 257 | 271 |
| 258 /** | 272 /** |
| 259 * Install an application on the device. | 273 * Install an application on the device. |
| 260 */ | 274 */ |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 } | 423 } |
| 410 | 424 |
| 411 static Future<AdbDevicePool> create() async { | 425 static Future<AdbDevicePool> create() async { |
| 412 var names = await AdbHelper.listDevices(); | 426 var names = await AdbHelper.listDevices(); |
| 413 var devices = names.map((id) => new AdbDevice(id)).toList(); | 427 var devices = names.map((id) => new AdbDevice(id)).toList(); |
| 414 if (devices.length == 0) { | 428 if (devices.length == 0) { |
| 415 throw new Exception( | 429 throw new Exception( |
| 416 'No android devices found. ' | 430 'No android devices found. ' |
| 417 'Please make sure "adb devices" shows your device!'); | 431 'Please make sure "adb devices" shows your device!'); |
| 418 } | 432 } |
| 433 print("Found ${devices.length} Android devices."); |
| 419 return new AdbDevicePool(devices); | 434 return new AdbDevicePool(devices); |
| 420 } | 435 } |
| 421 | 436 |
| 422 Future<AdbDevice> acquireDevice() async { | 437 Future<AdbDevice> acquireDevice() async { |
| 423 if (_idleDevices.length > 0) { | 438 if (_idleDevices.length > 0) { |
| 424 return _idleDevices.removeFirst(); | 439 return _idleDevices.removeFirst(); |
| 425 } else { | 440 } else { |
| 426 var completer = new Completer(); | 441 var completer = new Completer(); |
| 427 _waiter.add(completer); | 442 _waiter.add(completer); |
| 428 return completer.future; | 443 return completer.future; |
| 429 } | 444 } |
| 430 } | 445 } |
| 431 | 446 |
| 432 void releaseDevice(AdbDevice device) { | 447 void releaseDevice(AdbDevice device) { |
| 433 if (_waiter.length > 0) { | 448 if (_waiter.length > 0) { |
| 434 Completer completer = _waiter.removeFirst(); | 449 Completer completer = _waiter.removeFirst(); |
| 435 completer.complete(device); | 450 completer.complete(device); |
| 436 } else { | 451 } else { |
| 437 _idleDevices.add(device); | 452 _idleDevices.add(device); |
| 438 } | 453 } |
| 439 } | 454 } |
| 440 } | 455 } |
| OLD | NEW |