| 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"; |
| 8 import "dart:convert" show LineSplitter, UTF8; |
| 9 import "dart:core"; |
| 7 import "dart:io"; | 10 import "dart:io"; |
| 8 import "dart:async"; | |
| 9 import "dart:core"; | |
| 10 import "dart:utf"; | 11 import "dart:utf"; |
| 11 | 12 |
| 12 import "utils.dart"; | 13 import "utils.dart"; |
| 13 | 14 |
| 14 Future _executeCommand(String executable, | 15 Future _executeCommand(String executable, |
| 15 List<String> args, | 16 List<String> args, |
| 16 [String stdin = ""]) { | 17 [String stdin = ""]) { |
| 17 return _executeCommandRaw(executable, args, stdin).then((results) => null); | 18 return _executeCommandRaw(executable, args, stdin).then((results) => null); |
| 18 } | 19 } |
| 19 | 20 |
| 20 Future _executeCommandGetOutput(String executable, | 21 Future _executeCommandGetOutput(String executable, |
| 21 List<String> args, | 22 List<String> args, |
| 22 [String stdin = ""]) { | 23 [String stdin = ""]) { |
| 23 return _executeCommandRaw(executable, args, stdin) | 24 return _executeCommandRaw(executable, args, stdin) |
| 24 .then((output) => output); | 25 .then((output) => output); |
| 25 } | 26 } |
| 26 | 27 |
| 27 /** | 28 /** |
| 28 * [_executeCommandRaw] will write [stdin] to the standard input of the created | 29 * [_executeCommandRaw] will write [stdin] to the standard input of the created |
| 29 * process and will return a tuple (stdout, stderr). | 30 * process and will return a tuple (stdout, stderr). |
| 30 * | 31 * |
| 31 * If the exit code of the process was nonzero it will complete with an error. | 32 * If the exit code of the process was nonzero it will complete with an error. |
| 32 * If starting the process failed, it will complete with an error as well. | 33 * If starting the process failed, it will complete with an error as well. |
| 33 */ | 34 */ |
| 34 Future _executeCommandRaw(String executable, | 35 Future _executeCommandRaw(String executable, |
| 35 List<String> args, | 36 List<String> args, |
| 36 [String stdin = ""]) { | 37 [String stdin = ""]) { |
| 37 Future<String> getOutput(Stream<List<int>> stream) { | 38 Future<String> getOutput(Stream<List<int>> stream) { |
| 38 return stream.transform(new StringDecoder()).toList() | 39 return stream.transform(UTF8.decoder).toList() |
| 39 .then((data) => data.join("")); | 40 .then((data) => data.join("")); |
| 40 } | 41 } |
| 41 | 42 |
| 42 DebugLogger.info("Running: '\$ $executable ${args.join(' ')}'"); | 43 DebugLogger.info("Running: '\$ $executable ${args.join(' ')}'"); |
| 43 return Process.start(executable, args).then((Process process) { | 44 return Process.start(executable, args).then((Process process) { |
| 44 if (stdin != null && stdin != '') { | 45 if (stdin != null && stdin != '') { |
| 45 process.stdin.write(stdin); | 46 process.stdin.write(stdin); |
| 46 } | 47 } |
| 47 process.stdin.close(); | 48 process.stdin.close(); |
| 48 | 49 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 var portNumber = AdbServerPortPool.next(); | 106 var portNumber = AdbServerPortPool.next(); |
| 106 var args = ['-avd', '$avdName', '-port', "$portNumber" /*, '-gpu', 'on'*/]; | 107 var args = ['-avd', '$avdName', '-port', "$portNumber" /*, '-gpu', 'on'*/]; |
| 107 return Process.start("emulator64-arm", args).then((Process process) { | 108 return Process.start("emulator64-arm", args).then((Process process) { |
| 108 var adbDevice = new AdbDevice('emulator-$portNumber'); | 109 var adbDevice = new AdbDevice('emulator-$portNumber'); |
| 109 return new AndroidEmulator._private(portNumber, adbDevice, process); | 110 return new AndroidEmulator._private(portNumber, adbDevice, process); |
| 110 }); | 111 }); |
| 111 } | 112 } |
| 112 | 113 |
| 113 AndroidEmulator._private(this._port, this._adbDevice, this._emulatorProcess) { | 114 AndroidEmulator._private(this._port, this._adbDevice, this._emulatorProcess) { |
| 114 Stream<String> getLines(Stream s) { | 115 Stream<String> getLines(Stream s) { |
| 115 return s.transform(new StringDecoder()).transform(new LineTransformer()); | 116 return s.transform(UTF8.decoder).transform(new LineSplitter()); |
| 116 } | 117 } |
| 117 | 118 |
| 118 getLines(_emulatorProcess.stdout).listen((line) { | 119 getLines(_emulatorProcess.stdout).listen((line) { |
| 119 log("stdout: ${line.trim()}"); | 120 log("stdout: ${line.trim()}"); |
| 120 }); | 121 }); |
| 121 getLines(_emulatorProcess.stderr).listen((line) { | 122 getLines(_emulatorProcess.stderr).listen((line) { |
| 122 log("stderr: ${line.trim()}"); | 123 log("stderr: ${line.trim()}"); |
| 123 }); | 124 }); |
| 124 _emulatorProcess.exitCode.then((exitCode) { | 125 _emulatorProcess.exitCode.then((exitCode) { |
| 125 log("emulator exited with exitCode: $exitCode."); | 126 log("emulator exited with exitCode: $exitCode."); |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 */ | 316 */ |
| 316 class Intent { | 317 class Intent { |
| 317 String action; | 318 String action; |
| 318 String package; | 319 String package; |
| 319 String activity; | 320 String activity; |
| 320 String dataUri; | 321 String dataUri; |
| 321 | 322 |
| 322 Intent(this.action, this.package, this.activity, [this.dataUri]); | 323 Intent(this.action, this.package, this.activity, [this.dataUri]); |
| 323 } | 324 } |
| 324 | 325 |
| OLD | NEW |