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
5ac6f931
Commit
5ac6f931
authored
Jan 20, 2016
by
Devon Carew
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1305 from devoncarew/device_notification
Device notification
parents
5ad67975
8bb8e1d9
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
240 additions
and
66 deletions
+240
-66
daemon.dart
packages/flutter_tools/lib/src/commands/daemon.dart
+181
-45
device.dart
packages/flutter_tools/lib/src/device.dart
+26
-10
daemon_test.dart
packages/flutter_tools/test/daemon_test.dart
+19
-6
daemon_client.dart
packages/flutter_tools/tool/daemon_client.dart
+14
-5
No files found.
packages/flutter_tools/lib/src/commands/daemon.dart
View file @
5ac6f931
This diff is collapsed.
Click to expand it.
packages/flutter_tools/lib/src/device.dart
View file @
5ac6f931
...
...
@@ -21,8 +21,14 @@ abstract class Device {
return
_deviceCache
.
putIfAbsent
(
id
,
()
=>
constructor
(
id
));
}
static
void
removeFromCache
(
String
id
)
{
_deviceCache
.
remove
(
id
);
}
Device
.
_
(
this
.
id
);
String
get
name
;
/// Install an app package on the current device
bool
installApp
(
ApplicationPackage
app
);
...
...
@@ -532,20 +538,25 @@ class AndroidDevice extends Device {
String
modelID
;
String
deviceCodeName
;
bool
_connected
;
String
_adbPath
;
String
get
adbPath
=>
_adbPath
;
bool
_hasAdb
=
false
;
bool
_hasValidAndroid
=
false
;
factory
AndroidDevice
(
{
String
id:
null
,
String
productID:
null
,
String
modelID:
null
,
String
deviceCodeName:
null
})
{
factory
AndroidDevice
({
String
id:
null
,
String
productID:
null
,
String
modelID:
null
,
String
deviceCodeName:
null
,
bool
connected
})
{
AndroidDevice
device
=
Device
.
_unique
(
id
??
defaultDeviceID
,
(
String
id
)
=>
new
AndroidDevice
.
_
(
id
));
device
.
productID
=
productID
;
device
.
modelID
=
modelID
;
device
.
deviceCodeName
=
deviceCodeName
;
if
(
connected
!=
null
)
device
.
_connected
=
connected
;
return
device
;
}
...
...
@@ -553,7 +564,7 @@ class AndroidDevice extends Device {
/// we don't have to rely on the test setup having adb available to it.
static
List
<
AndroidDevice
>
getAttachedDevices
([
AndroidDevice
mockAndroid
])
{
List
<
AndroidDevice
>
devices
=
[];
String
adbPath
=
(
mockAndroid
!=
null
)
?
mockAndroid
.
adbPath
:
_
getAdbPath
();
String
adbPath
=
(
mockAndroid
!=
null
)
?
mockAndroid
.
adbPath
:
getAdbPath
();
try
{
runCheckedSync
([
adbPath
,
'version'
]);
...
...
@@ -623,7 +634,7 @@ class AndroidDevice extends Device {
}
AndroidDevice
.
_
(
id
)
:
super
.
_
(
id
)
{
_adbPath
=
_
getAdbPath
();
_adbPath
=
getAdbPath
();
_hasAdb
=
_checkForAdb
();
// Checking for [minApiName] only needs to be done if we are starting an
...
...
@@ -655,7 +666,7 @@ class AndroidDevice extends Device {
}
}
static
String
_
getAdbPath
()
{
static
String
getAdbPath
()
{
if
(
Platform
.
environment
.
containsKey
(
'ANDROID_HOME'
))
{
String
androidHomeDir
=
Platform
.
environment
[
'ANDROID_HOME'
];
String
adbPath1
=
path
.
join
(
androidHomeDir
,
'sdk'
,
'platform-tools'
,
'adb'
);
...
...
@@ -782,6 +793,8 @@ class AndroidDevice extends Device {
return
CryptoUtils
.
bytesToHex
(
sha1
.
close
());
}
String
get
name
=>
modelID
;
@override
bool
isAppInstalled
(
ApplicationPackage
app
)
{
if
(!
isConnected
())
{
...
...
@@ -992,8 +1005,11 @@ class AndroidDevice extends Device {
return
null
;
}
@override
bool
isConnected
()
=>
_hasValidAndroid
;
bool
isConnected
()
=>
_connected
!=
null
?
_connected
:
_hasValidAndroid
;
void
setConnected
(
bool
value
)
{
_connected
=
value
;
}
}
class
DeviceStore
{
...
...
packages/flutter_tools/test/daemon_test.dart
View file @
5ac6f931
...
...
@@ -26,9 +26,9 @@ defineTests() {
StreamController
<
Map
>
responses
=
new
StreamController
();
daemon
=
new
Daemon
(
commands
.
stream
,
(
Map
result
)
=>
responses
.
add
(
result
)
(
Map
<
String
,
dynamic
>
result
)
=>
responses
.
add
(
result
)
);
commands
.
add
({
'id'
:
0
,
'
event
'
:
'daemon.version'
});
commands
.
add
({
'id'
:
0
,
'
method
'
:
'daemon.version'
});
Map
response
=
await
responses
.
stream
.
first
;
expect
(
response
[
'id'
],
0
);
expect
(
response
[
'result'
],
isNotEmpty
);
...
...
@@ -40,9 +40,9 @@ defineTests() {
StreamController
<
Map
>
responses
=
new
StreamController
();
daemon
=
new
Daemon
(
commands
.
stream
,
(
Map
result
)
=>
responses
.
add
(
result
)
(
Map
<
String
,
dynamic
>
result
)
=>
responses
.
add
(
result
)
);
commands
.
add
({
'id'
:
0
,
'
event
'
:
'daemon.shutdown'
});
commands
.
add
({
'id'
:
0
,
'
method
'
:
'daemon.shutdown'
});
return
daemon
.
onExit
.
then
((
int
code
)
{
expect
(
code
,
0
);
});
...
...
@@ -56,7 +56,7 @@ defineTests() {
StreamController
<
Map
>
responses
=
new
StreamController
();
daemon
=
new
Daemon
(
commands
.
stream
,
(
Map
result
)
=>
responses
.
add
(
result
),
(
Map
<
String
,
dynamic
>
result
)
=>
responses
.
add
(
result
),
daemonCommand:
command
);
...
...
@@ -71,10 +71,23 @@ defineTests() {
when
(
mockDevices
.
iOSSimulator
.
isConnected
()).
thenReturn
(
false
);
when
(
mockDevices
.
iOSSimulator
.
stopApp
(
any
)).
thenReturn
(
false
);
commands
.
add
({
'id'
:
0
,
'
event
'
:
'app.stopAll'
});
commands
.
add
({
'id'
:
0
,
'
method
'
:
'app.stopAll'
});
Map
response
=
await
responses
.
stream
.
first
;
expect
(
response
[
'id'
],
0
);
expect
(
response
[
'result'
],
true
);
});
test
(
'device.getDevices'
,
()
async
{
StreamController
<
Map
>
commands
=
new
StreamController
();
StreamController
<
Map
>
responses
=
new
StreamController
();
daemon
=
new
Daemon
(
commands
.
stream
,
(
Map
<
String
,
dynamic
>
result
)
=>
responses
.
add
(
result
)
);
commands
.
add
({
'id'
:
0
,
'method'
:
'device.getDevices'
});
Map
response
=
await
responses
.
stream
.
first
;
expect
(
response
[
'id'
],
0
);
expect
(
response
[
'result'
],
isList
);
});
});
}
packages/flutter_tools/tool/daemon_client.dart
View file @
5ac6f931
...
...
@@ -7,8 +7,15 @@ import 'dart:io';
Process
daemon
;
// To use, start from the console and enter:
// version: print version
// shutdown: terminate the server
// start: start an app
// stopAll: stop any running app
// devices: list devices
main
()
async
{
daemon
=
await
Process
.
start
(
'
dart'
,
[
'bin/flutter_tools.dart'
,
'daemon'
]);
daemon
=
await
Process
.
start
(
'
flutter'
,
[
'daemon'
]);
print
(
'daemon process started, pid:
${daemon.pid}
'
);
daemon
.
stdout
...
...
@@ -20,13 +27,15 @@ main() async {
stdout
.
write
(
'> '
);
stdin
.
transform
(
UTF8
.
decoder
).
transform
(
const
LineSplitter
()).
listen
((
String
line
)
{
if
(
line
==
'version'
||
line
==
'v'
)
{
_send
({
'
event
'
:
'daemon.version'
});
_send
({
'
method
'
:
'daemon.version'
});
}
else
if
(
line
==
'shutdown'
||
line
==
'q'
)
{
_send
({
'
event
'
:
'daemon.shutdown'
});
_send
({
'
method
'
:
'daemon.shutdown'
});
}
else
if
(
line
==
'start'
)
{
_send
({
'
event
'
:
'app.start'
});
_send
({
'
method
'
:
'app.start'
});
}
else
if
(
line
==
'stopAll'
)
{
_send
({
'event'
:
'app.stopAll'
});
_send
({
'method'
:
'app.stopAll'
});
}
else
if
(
line
==
'devices'
)
{
_send
({
'method'
:
'device.getDevices'
});
}
else
{
print
(
'command not understood:
${line}
'
);
}
...
...
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