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
00c7734c
Commit
00c7734c
authored
Jun 02, 2016
by
Jason Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tools daemon handlers for discovering apps and forwarding device ports (#4324)
parent
8ec26f02
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
92 additions
and
14 deletions
+92
-14
android_device.dart
packages/flutter_tools/lib/src/android/android_device.dart
+22
-0
daemon.dart
packages/flutter_tools/lib/src/commands/daemon.dart
+59
-14
device.dart
packages/flutter_tools/lib/src/device.dart
+11
-0
No files found.
packages/flutter_tools/lib/src/android/android_device.dart
View file @
00c7734c
...
...
@@ -513,6 +513,28 @@ class AndroidDevice extends Device {
return
new
Future
<
bool
>.
value
(
true
);
}
@override
Future
<
List
<
DiscoveredApp
>>
discoverApps
()
{
RegExp
discoverExp
=
new
RegExp
(
r'DISCOVER: (.*)'
);
List
<
DiscoveredApp
>
result
=
<
DiscoveredApp
>[];
StreamSubscription
<
String
>
logs
=
logReader
.
logLines
.
listen
((
String
line
)
{
Match
match
=
discoverExp
.
firstMatch
(
line
);
if
(
match
!=
null
)
{
Map
<
String
,
dynamic
>
app
=
JSON
.
decode
(
match
.
group
(
1
));
result
.
add
(
new
DiscoveredApp
(
app
[
'id'
],
app
[
'observatoryPort'
]));
}
});
runCheckedSync
(
adbCommandForDevice
(<
String
>[
'shell'
,
'am'
,
'broadcast'
,
'-a'
,
'io.flutter.view.DISCOVER'
]));
return
new
Future
<
List
<
DiscoveredApp
>>.
delayed
(
new
Duration
(
seconds:
1
),
()
{
logs
.
cancel
();
return
result
;
});
}
}
// 015d172c98400a03 device usb:340787200X product:nakasi model:Nexus_7 device:grouper
...
...
packages/flutter_tools/lib/src/commands/daemon.dart
View file @
00c7734c
...
...
@@ -237,6 +237,23 @@ class DaemonDomain extends Domain {
}
}
/// Return the device matching the deviceId field in the args.
Future
<
Device
>
_getDevice
(
Daemon
daemon
,
Map
<
String
,
dynamic
>
args
)
async
{
if
(
args
==
null
||
args
[
'deviceId'
]
is
!
String
)
throw
'deviceId is required'
;
List
<
Device
>
devices
=
await
daemon
.
deviceDomain
.
getDevices
();
Device
device
=
devices
.
firstWhere
(
(
Device
device
)
=>
device
.
id
==
args
[
'deviceId'
],
orElse:
()
=>
null
);
if
(
device
==
null
)
throw
"device '
${args['deviceId']}
' not found"
;
return
device
;
}
/// This domain responds to methods like [start] and [stop].
///
/// It'll be extended to fire events for when applications start, stop, and
...
...
@@ -245,14 +262,11 @@ class AppDomain extends Domain {
AppDomain
(
Daemon
daemon
)
:
super
(
daemon
,
'app'
)
{
registerHandler
(
'start'
,
start
);
registerHandler
(
'stop'
,
stop
);
registerHandler
(
'discover'
,
discover
);
}
Future
<
dynamic
>
start
(
Map
<
String
,
dynamic
>
args
)
async
{
if
(
args
==
null
||
args
[
'deviceId'
]
is
!
String
)
throw
"deviceId is required"
;
Device
device
=
await
_getDevice
(
args
[
'deviceId'
]);
if
(
device
==
null
)
throw
"device '
${args['deviceId']}
' not found"
;
Device
device
=
await
_getDevice
(
daemon
,
args
);
if
(
args
[
'projectDirectory'
]
is
!
String
)
throw
"projectDirectory is required"
;
...
...
@@ -282,12 +296,8 @@ class AppDomain extends Domain {
return
null
;
}
Future
<
bool
>
stop
(
dynamic
args
)
async
{
if
(
args
==
null
||
args
[
'deviceId'
]
is
!
String
)
throw
"deviceId is required"
;
Device
device
=
await
_getDevice
(
args
[
'deviceId'
]);
if
(
device
==
null
)
throw
"device '
${args['deviceId']}
' not found"
;
Future
<
bool
>
stop
(
Map
<
String
,
dynamic
>
args
)
async
{
Device
device
=
await
_getDevice
(
daemon
,
args
);
if
(
args
[
'projectDirectory'
]
is
!
String
)
throw
"projectDirectory is required"
;
...
...
@@ -306,9 +316,12 @@ class AppDomain extends Domain {
}
}
Future
<
Device
>
_getDevice
(
String
deviceId
)
async
{
List
<
Device
>
devices
=
await
daemon
.
deviceDomain
.
getDevices
();
return
devices
.
firstWhere
((
Device
device
)
=>
device
.
id
==
deviceId
,
orElse:
()
=>
null
);
Future
<
List
<
Map
<
String
,
dynamic
>>>
discover
(
Map
<
String
,
dynamic
>
args
)
async
{
Device
device
=
await
_getDevice
(
daemon
,
args
);
List
<
DiscoveredApp
>
apps
=
await
device
.
discoverApps
();
return
apps
.
map
((
DiscoveredApp
app
)
=>
<
String
,
dynamic
>{
'id'
:
app
.
id
,
'observatoryDevicePort'
:
app
.
observatoryPort
}
).
toList
();
}
}
...
...
@@ -321,6 +334,8 @@ class DeviceDomain extends Domain {
registerHandler
(
'getDevices'
,
getDevices
);
registerHandler
(
'enable'
,
enable
);
registerHandler
(
'disable'
,
disable
);
registerHandler
(
'forward'
,
forward
);
registerHandler
(
'unforward'
,
unforward
);
PollingDeviceDiscovery
deviceDiscovery
=
new
AndroidDevices
();
if
(
deviceDiscovery
.
supportsPlatform
)
...
...
@@ -369,6 +384,36 @@ class DeviceDomain extends Domain {
return
new
Future
<
Null
>.
value
();
}
/// Forward a host port to a device port.
Future
<
Map
<
String
,
dynamic
>>
forward
(
Map
<
String
,
dynamic
>
args
)
async
{
Device
device
=
await
_getDevice
(
daemon
,
args
);
if
(
args
[
'devicePort'
]
is
!
int
)
throw
'devicePort is required'
;
int
devicePort
=
args
[
'devicePort'
];
int
hostPort
=
args
[
'hostPort'
];
hostPort
=
await
device
.
portForwarder
.
forward
(
devicePort
,
hostPort:
hostPort
);
return
<
String
,
dynamic
>{
'hostPort'
:
hostPort
};
}
/// Removes a forwarded port.
Future
<
Null
>
unforward
(
Map
<
String
,
dynamic
>
args
)
async
{
Device
device
=
await
_getDevice
(
daemon
,
args
);
if
(
args
[
'devicePort'
]
is
!
int
)
throw
'devicePort is required'
;
int
devicePort
=
args
[
'devicePort'
];
if
(
args
[
'hostPort'
]
is
!
int
)
throw
'hostPort is required'
;
int
hostPort
=
args
[
'hostPort'
];
device
.
portForwarder
.
unforward
(
new
ForwardedPort
(
hostPort
,
devicePort
));
}
@override
void
dispose
()
{
for
(
PollingDeviceDiscovery
discoverer
in
_discoverers
)
{
...
...
packages/flutter_tools/lib/src/device.dart
View file @
00c7734c
...
...
@@ -205,6 +205,10 @@ abstract class Device {
Future
<
bool
>
takeScreenshot
(
File
outputFile
)
=>
new
Future
<
bool
>.
error
(
'unimplemented'
);
/// Find the apps that are currently running on this device.
Future
<
List
<
DiscoveredApp
>>
discoverApps
()
=>
new
Future
<
List
<
DiscoveredApp
>>.
value
(<
DiscoveredApp
>[]);
@override
int
get
hashCode
=>
id
.
hashCode
;
...
...
@@ -333,3 +337,10 @@ abstract class DeviceLogReader {
@override
String
toString
()
=>
name
;
}
/// Describes an app running on the device.
class
DiscoveredApp
{
DiscoveredApp
(
this
.
id
,
this
.
observatoryPort
);
final
String
id
;
final
int
observatoryPort
;
}
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