Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
f423951c
Commit
f423951c
authored
Feb 04, 2016
by
Devon Carew
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1619 from devoncarew/device_names
get the adb device name when using the adb server
parents
5a793dd4
4ff43bf4
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
3 deletions
+37
-3
adb.dart
packages/flutter_tools/lib/src/android/adb.dart
+37
-3
No files found.
packages/flutter_tools/lib/src/android/adb.dart
View file @
f423951c
...
...
@@ -19,6 +19,8 @@ class Adb {
final
String
adbPath
;
Map
<
String
,
String
>
_idToNameCache
=
<
String
,
String
>{};
bool
exists
()
{
try
{
runCheckedSync
([
adbPath
,
'version'
]);
...
...
@@ -85,7 +87,7 @@ class Adb {
socket
=
await
Socket
.
connect
(
InternetAddress
.
LOOPBACK_IP_V4
,
adbServerPort
);
printTrace
(
'--> host:track-devices'
);
socket
.
add
(
_createAdbRequest
(
'host:track-devices'
));
socket
.
listen
((
List
<
int
>
data
)
{
socket
.
listen
((
List
<
int
>
data
)
async
{
String
stringResult
=
new
String
.
fromCharCodes
(
data
);
printTrace
(
'<--
${stringResult.trim()}
'
);
_AdbServerResponse
response
=
new
_AdbServerResponse
(
...
...
@@ -99,9 +101,13 @@ class Adb {
if
(
devicesText
.
isEmpty
)
{
controller
.
add
(<
AdbDevice
>[]);
}
else
{
controller
.
add
(
devicesText
.
split
(
'
\n
'
).
map
((
String
deviceInfo
)
{
List
<
AdbDevice
>
devices
=
devicesText
.
split
(
'
\n
'
).
map
((
String
deviceInfo
)
{
return
new
AdbDevice
(
deviceInfo
);
}).
toList
());
}).
toList
();
await
_populateDeviceNames
(
devices
);
controller
.
add
(
devices
);
}
});
socket
.
done
.
then
((
_
)
=>
controller
.
close
());
...
...
@@ -112,6 +118,26 @@ class Adb {
return
controller
.
stream
;
}
Future
_populateDeviceNames
(
List
<
AdbDevice
>
devices
)
async
{
for
(
AdbDevice
device
in
devices
)
{
if
(
device
.
modelID
==
null
)
{
// If we don't have a name of a device in our cache, call `device -l` to populate it.
if
(
_idToNameCache
[
device
.
id
]
==
null
)
await
_populateDeviceCache
();
// Set the device name from the cached name. Adb device notifications only
// have IDs, not names. We get the name by calling `listDevices()`.
device
.
modelID
=
_idToNameCache
[
device
.
id
];
}
}
}
Future
_populateDeviceCache
()
async
{
List
<
AdbDevice
>
devices
=
await
listDevices
();
for
(
AdbDevice
device
in
devices
)
_idToNameCache
[
device
.
id
]
=
device
.
modelID
;
}
Future
<
String
>
_sendAdbServerCommand
(
String
command
)
async
{
Socket
socket
=
await
Socket
.
connect
(
InternetAddress
.
LOOPBACK_IP_V4
,
adbServerPort
);
...
...
@@ -151,6 +177,10 @@ class AdbDevice {
}
}
}
// Convert `Nexus_7` / `Nexus_5X` style names to `Nexus 7` ones.
if
(
modelID
!=
null
)
modelID
=
modelID
.
replaceAll
(
'_'
,
' '
);
}
static
final
RegExp
deviceRegex
=
new
RegExp
(
r'^(\S+)\s+(\S+)(.*)'
);
...
...
@@ -168,6 +198,10 @@ class AdbDevice {
/// Device model; can be null. `XT1045`, `Nexus_7`
String
get
modelID
=>
_info
[
'model'
];
set
modelID
(
String
value
)
{
_info
[
'model'
]
=
value
;
}
/// Device code name; can be null. `peregrine`, `grouper`
String
get
deviceCodeName
=>
_info
[
'device'
];
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment