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
43aaf50e
Commit
43aaf50e
authored
Oct 07, 2015
by
Ian Fischer
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #78 from iansf/ios_start
Add implementation of start and stop commands for iOS.
parents
72cc4d6f
844678dd
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
146 additions
and
18 deletions
+146
-18
device.dart
packages/flutter_tools/lib/src/device.dart
+49
-1
process.dart
packages/flutter_tools/lib/src/process.dart
+12
-0
start.dart
packages/flutter_tools/lib/src/start.dart
+14
-4
stop.dart
packages/flutter_tools/lib/src/stop.dart
+20
-10
start_test.dart
packages/flutter_tools/test/start_test.dart
+26
-1
stop_test.dart
packages/flutter_tools/test/stop_test.dart
+25
-2
No files found.
packages/flutter_tools/lib/src/device.dart
View file @
43aaf50e
...
...
@@ -56,6 +56,12 @@ abstract class _Device {
/// Check if the current version of the given app is already installed
bool
isAppInstalled
(
ApplicationPackage
app
);
/// Start an app package on the current device
Future
<
bool
>
startApp
(
ApplicationPackage
app
);
/// Stop an app package on the current device
Future
<
bool
>
stopApp
(
ApplicationPackage
app
);
}
class
IOSDevice
extends
_Device
{
...
...
@@ -80,6 +86,9 @@ class IOSDevice extends _Device {
String
_informerPath
;
String
get
informerPath
=>
_informerPath
;
String
_debuggerPath
;
String
get
debuggerPath
=>
_debuggerPath
;
String
_name
;
String
get
name
=>
_name
;
...
...
@@ -93,6 +102,7 @@ class IOSDevice extends _Device {
_installerPath
=
_checkForCommand
(
'ideviceinstaller'
);
_listerPath
=
_checkForCommand
(
'idevice_id'
);
_informerPath
=
_checkForCommand
(
'ideviceinfo'
);
_debuggerPath
=
_checkForCommand
(
'idevicedebug'
);
}
static
List
<
IOSDevice
>
getAttachedDevices
([
IOSDevice
mockIOS
])
{
...
...
@@ -160,6 +170,37 @@ class IOSDevice extends _Device {
@override
bool
isAppInstalled
(
ApplicationPackage
app
)
{
try
{
String
apps
=
runCheckedSync
([
installerPath
,
'-l'
]);
if
(
new
RegExp
(
app
.
appPackageID
,
multiLine:
true
).
hasMatch
(
apps
))
{
return
true
;
}
}
catch
(
e
)
{
return
false
;
}
return
false
;
}
@override
Future
<
bool
>
startApp
(
ApplicationPackage
app
)
async
{
if
(!
isAppInstalled
(
app
))
{
return
false
;
}
// idevicedebug hangs forever after launching the app, so kill it after
// giving it plenty of time to send the launch command.
return
runAndKill
(
[
debuggerPath
,
'run'
,
app
.
appPackageID
],
new
Duration
(
seconds:
3
)).
then
(
(
_
)
{
return
true
;
},
onError:
(
e
)
{
_logging
.
info
(
'Failure running
$debuggerPath
: '
,
e
);
return
false
;
});
}
@override
Future
<
bool
>
stopApp
(
ApplicationPackage
app
)
async
{
// Currently we don't have a way to stop an app running on iOS.
return
false
;
}
}
...
...
@@ -458,7 +499,14 @@ class AndroidDevice extends _Device {
return
true
;
}
bool
stop
(
AndroidApk
apk
)
{
@override
Future
<
bool
>
startApp
(
AndroidApk
apk
)
async
{
// Android currently has to be started with startServer(...).
assert
(
false
);
return
false
;
}
Future
<
bool
>
stopApp
(
AndroidApk
apk
)
async
{
// Turn off reverse port forwarding
runSync
([
adbPath
,
'reverse'
,
'--remove'
,
'tcp:
$_serverPort
'
]);
// Stop the app
...
...
packages/flutter_tools/lib/src/process.dart
View file @
43aaf50e
...
...
@@ -28,6 +28,18 @@ Future<int> runCommandAndStreamOutput(List<String> cmd,
return
proc
.
exitCode
;
}
Future
runAndKill
(
List
<
String
>
cmd
,
Duration
timeout
)
async
{
_logging
.
info
(
cmd
.
join
(
' '
));
Future
<
Process
>
proc
=
Process
.
start
(
cmd
[
0
],
cmd
.
getRange
(
1
,
cmd
.
length
).
toList
(),
mode:
ProcessStartMode
.
DETACHED
);
return
new
Future
.
delayed
(
timeout
,
()
async
{
_logging
.
info
(
'Intentionally killing
${cmd[0]}
'
);
Process
.
killPid
((
await
proc
).
pid
);
});
}
/// Run cmd and return stdout.
/// Throws an error if cmd exits with a non-zero value.
String
runCheckedSync
(
List
<
String
>
cmd
)
=>
...
...
packages/flutter_tools/lib/src/start.dart
View file @
43aaf50e
...
...
@@ -41,22 +41,26 @@ class StartCommand extends Command {
if
(
android
==
null
)
{
android
=
new
AndroidDevice
();
}
if
(
ios
==
null
)
{
ios
=
new
IOSDevice
();
}
bool
startedSomewhere
=
false
;
bool
poke
=
argResults
[
'poke'
];
if
(!
poke
)
{
StopCommand
stopper
=
new
StopCommand
(
android
);
StopCommand
stopper
=
new
StopCommand
(
android
:
android
,
ios:
ios
);
stopper
.
stop
();
// Only install if the user did not specify a poke
InstallCommand
installer
=
new
InstallCommand
(
android:
android
,
ios:
ios
);
startedSomewhere
=
installer
.
install
();
installer
.
install
();
}
Map
<
BuildPlatform
,
ApplicationPackage
>
packages
=
ApplicationPackageFactory
.
getAvailableApplicationPackages
();
bool
startedOnAndroid
=
false
;
if
(
android
.
isConnected
())
{
Map
<
BuildPlatform
,
ApplicationPackage
>
packages
=
ApplicationPackageFactory
.
getAvailableApplicationPackages
();
ApplicationPackage
androidApp
=
packages
[
BuildPlatform
.
android
];
String
target
=
path
.
absolute
(
argResults
[
'target'
]);
...
...
@@ -64,6 +68,12 @@ class StartCommand extends Command {
target
,
poke
,
argResults
[
'checked'
],
androidApp
);
}
if
(
ios
.
isConnected
())
{
ApplicationPackage
iosApp
=
packages
[
BuildPlatform
.
iOS
];
startedSomewhere
=
await
ios
.
startApp
(
iosApp
)
||
startedSomewhere
;
}
if
(
startedSomewhere
||
startedOnAndroid
)
{
return
0
;
}
else
{
...
...
packages/flutter_tools/lib/src/stop.dart
View file @
43aaf50e
...
...
@@ -17,29 +17,39 @@ class StopCommand extends Command {
final
name
=
'stop'
;
final
description
=
'Stop your Flutter app on all attached devices.'
;
AndroidDevice
android
=
null
;
IOSDevice
ios
=
null
;
StopCommand
(
[
this
.
android
]
);
StopCommand
(
{
this
.
android
,
this
.
ios
}
);
@override
Future
<
int
>
run
()
async
{
if
(
android
==
null
)
{
android
=
new
AndroidDevice
();
}
if
(
stop
())
{
if
(
await
stop
())
{
return
0
;
}
else
{
return
2
;
}
}
bool
stop
()
{
Future
<
bool
>
stop
()
async
{
if
(
android
==
null
)
{
android
=
new
AndroidDevice
();
}
if
(
ios
==
null
)
{
ios
=
new
IOSDevice
();
}
bool
stoppedSomething
=
false
;
Map
<
BuildPlatform
,
ApplicationPackage
>
packages
=
ApplicationPackageFactory
.
getAvailableApplicationPackages
();
if
(
android
.
isConnected
())
{
Map
<
BuildPlatform
,
ApplicationPackage
>
packages
=
ApplicationPackageFactory
.
getAvailableApplicationPackages
();
ApplicationPackage
androidApp
=
packages
[
BuildPlatform
.
android
];
stoppedSomething
=
android
.
stop
(
androidApp
)
||
stoppedSomething
;
stoppedSomething
=
await
android
.
stopApp
(
androidApp
)
||
stoppedSomething
;
}
if
(
ios
.
isConnected
())
{
ApplicationPackage
iosApp
=
packages
[
BuildPlatform
.
iOS
];
stoppedSomething
=
await
ios
.
stopApp
(
iosApp
)
||
stoppedSomething
;
}
return
stoppedSomething
;
...
...
packages/flutter_tools/test/start_test.dart
View file @
43aaf50e
...
...
@@ -21,11 +21,36 @@ defineTests() {
MockAndroidDevice
android
=
new
MockAndroidDevice
();
when
(
android
.
isConnected
()).
thenReturn
(
true
);
when
(
android
.
installApp
(
any
)).
thenReturn
(
true
);
when
(
android
.
stop
(
any
)).
thenReturn
(
true
);
when
(
android
.
startServer
(
any
,
any
,
any
,
any
)).
thenReturn
(
true
);
when
(
android
.
stopApp
(
any
)).
thenReturn
(
true
);
MockIOSDevice
ios
=
new
MockIOSDevice
();
when
(
ios
.
isConnected
()).
thenReturn
(
false
);
when
(
ios
.
installApp
(
any
)).
thenReturn
(
false
);
when
(
ios
.
startApp
(
any
)).
thenReturn
(
false
);
when
(
ios
.
startApp
(
any
)).
thenReturn
(
false
);
StartCommand
command
=
new
StartCommand
(
android:
android
,
ios:
ios
);
CommandRunner
runner
=
new
CommandRunner
(
'test_flutter'
,
''
)
..
addCommand
(
command
);
runner
.
run
([
'start'
]).
then
((
int
code
)
=>
expect
(
code
,
equals
(
0
)));
});
test
(
'returns 0 when iOS is connected and ready to be started'
,
()
{
applicationPackageSetup
();
MockAndroidDevice
android
=
new
MockAndroidDevice
();
when
(
android
.
isConnected
()).
thenReturn
(
false
);
when
(
android
.
installApp
(
any
)).
thenReturn
(
false
);
when
(
android
.
startServer
(
any
,
any
,
any
,
any
)).
thenReturn
(
false
);
when
(
android
.
stopApp
(
any
)).
thenReturn
(
false
);
MockIOSDevice
ios
=
new
MockIOSDevice
();
when
(
ios
.
isConnected
()).
thenReturn
(
true
);
when
(
ios
.
installApp
(
any
)).
thenReturn
(
true
);
when
(
ios
.
startApp
(
any
)).
thenReturn
(
true
);
when
(
ios
.
stopApp
(
any
)).
thenReturn
(
false
);
StartCommand
command
=
new
StartCommand
(
android:
android
,
ios:
ios
);
...
...
packages/flutter_tools/test/stop_test.dart
View file @
43aaf50e
...
...
@@ -20,8 +20,31 @@ defineTests() {
MockAndroidDevice
android
=
new
MockAndroidDevice
();
when
(
android
.
isConnected
()).
thenReturn
(
true
);
when
(
android
.
stop
(
any
)).
thenReturn
(
true
);
StopCommand
command
=
new
StopCommand
(
android
);
when
(
android
.
stopApp
(
any
)).
thenReturn
(
true
);
MockIOSDevice
ios
=
new
MockIOSDevice
();
when
(
ios
.
isConnected
()).
thenReturn
(
false
);
when
(
ios
.
stopApp
(
any
)).
thenReturn
(
false
);
StopCommand
command
=
new
StopCommand
(
android:
android
,
ios:
ios
);
CommandRunner
runner
=
new
CommandRunner
(
'test_flutter'
,
''
)
..
addCommand
(
command
);
runner
.
run
([
'stop'
]).
then
((
int
code
)
=>
expect
(
code
,
equals
(
0
)));
});
test
(
'returns 0 when iOS is connected and ready to be stopped'
,
()
{
applicationPackageSetup
();
MockAndroidDevice
android
=
new
MockAndroidDevice
();
when
(
android
.
isConnected
()).
thenReturn
(
false
);
when
(
android
.
stopApp
(
any
)).
thenReturn
(
false
);
MockIOSDevice
ios
=
new
MockIOSDevice
();
when
(
ios
.
isConnected
()).
thenReturn
(
true
);
when
(
ios
.
stopApp
(
any
)).
thenReturn
(
true
);
StopCommand
command
=
new
StopCommand
(
android:
android
,
ios:
ios
);
CommandRunner
runner
=
new
CommandRunner
(
'test_flutter'
,
''
)
..
addCommand
(
command
);
...
...
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