Commit 2727954d authored by Devon Carew's avatar Devon Carew

review comments

parent 077ee32e
...@@ -13,17 +13,17 @@ import '../base/process.dart'; ...@@ -13,17 +13,17 @@ import '../base/process.dart';
/// A wrapper around the `adb` command-line tool and the adb server. /// A wrapper around the `adb` command-line tool and the adb server.
class Adb { class Adb {
Adb(this.adbPath);
static const int adbServerPort = 5037; static const int adbServerPort = 5037;
final String adbPath; final String adbPath;
Adb(this.adbPath);
bool exists() { bool exists() {
try { try {
runCheckedSync([adbPath, 'version']); runCheckedSync([adbPath, 'version']);
return true; return true;
} catch (_) { } catch (exception) {
return false; return false;
} }
} }
...@@ -68,7 +68,8 @@ class Adb { ...@@ -68,7 +68,8 @@ class Adb {
if (message.isEmpty) if (message.isEmpty)
return <AdbDevice>[]; return <AdbDevice>[];
return message.split('\n').map( return message.split('\n').map(
(String deviceInfo) => new AdbDevice(deviceInfo)).toList(); (String deviceInfo) => new AdbDevice(deviceInfo)
).toList();
} }
/// Listen to device activations and deactivations via the asb server's /// Listen to device activations and deactivations via the asb server's
...@@ -131,16 +132,6 @@ class Adb { ...@@ -131,16 +132,6 @@ class Adb {
} }
class AdbDevice { class AdbDevice {
static final RegExp deviceRegex = new RegExp(r'^(\S+)\s+(\S+)(.*)');
/// Always non-null; something like `TA95000FQA`.
String id;
/// device, offline, unauthorized.
String status;
Map<String, String> _info = <String, String>{};
AdbDevice(String deviceInfo) { AdbDevice(String deviceInfo) {
// 'TA95000FQA device' // 'TA95000FQA device'
// 'TA95000FQA device usb:340787200X product:peregrine_retus model:XT1045 device:peregrine' // 'TA95000FQA device usb:340787200X product:peregrine_retus model:XT1045 device:peregrine'
...@@ -162,6 +153,16 @@ class AdbDevice { ...@@ -162,6 +153,16 @@ class AdbDevice {
} }
} }
static final RegExp deviceRegex = new RegExp(r'^(\S+)\s+(\S+)(.*)');
/// Always non-null; something like `TA95000FQA`.
String id;
/// device, offline, unauthorized.
String status;
final Map<String, String> _info = <String, String>{};
bool get isAvailable => status == 'device'; bool get isAvailable => status == 'device';
/// Device model; can be null. `XT1045`, `Nexus_7` /// Device model; can be null. `XT1045`, `Nexus_7`
...@@ -173,7 +174,14 @@ class AdbDevice { ...@@ -173,7 +174,14 @@ class AdbDevice {
/// Device product; can be null. `peregrine_retus`, `nakasi` /// Device product; can be null. `peregrine_retus`, `nakasi`
String get productID => _info['product']; String get productID => _info['product'];
operator==(other) => other is AdbDevice && other.id == id; bool operator ==(dynamic other) {
if (identical(this, other))
return true;
if (other is! AdbDevice)
return false;
final AdbDevice typedOther = other;
return id == typedOther.id;
}
int get hashCode => id.hashCode; int get hashCode => id.hashCode;
...@@ -191,17 +199,14 @@ List<int> _createAdbRequest(String payload) { ...@@ -191,17 +199,14 @@ List<int> _createAdbRequest(String payload) {
// A 4-byte hexadecimal string giving the length of the payload. // A 4-byte hexadecimal string giving the length of the payload.
String prefix = data.length.toRadixString(16).padLeft(4, '0'); String prefix = data.length.toRadixString(16).padLeft(4, '0');
List<int> result = new List<int>(); List<int> result = <int>[];
result.addAll(prefix.codeUnits); result.addAll(prefix.codeUnits);
result.addAll(data); result.addAll(data);
return result; return result;
} }
class _AdbServerResponse { class _AdbServerResponse {
String status; _AdbServerResponse(String text, { bool noStatus: false }) {
String message;
_AdbServerResponse(String text, {bool noStatus: false}) {
if (noStatus) { if (noStatus) {
message = text; message = text;
} else { } else {
...@@ -217,6 +222,9 @@ class _AdbServerResponse { ...@@ -217,6 +222,9 @@ class _AdbServerResponse {
} }
} }
String status;
String message;
bool get isOkay => status == 'OKAY'; bool get isOkay => status == 'OKAY';
bool get isFail => status == 'FAIL'; bool get isFail => status == 'FAIL';
......
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