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
a599c23b
Unverified
Commit
a599c23b
authored
Feb 02, 2022
by
Jenn Magder
Committed by
GitHub
Feb 02, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Disallow running on unsupported devices (#97338)
parent
4cca04dd
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
79 additions
and
14 deletions
+79
-14
user_messages.dart
packages/flutter_tools/lib/src/base/user_messages.dart
+2
-2
device.dart
packages/flutter_tools/lib/src/device.dart
+2
-1
flutter_command.dart
packages/flutter_tools/lib/src/runner/flutter_command.dart
+6
-0
run_test.dart
.../flutter_tools/test/commands.shard/hermetic/run_test.dart
+30
-0
device_test.dart
packages/flutter_tools/test/general.shard/device_test.dart
+34
-9
flutter_run_test.dart
...lutter_tools/test/integration.shard/flutter_run_test.dart
+1
-1
fake_devices.dart
packages/flutter_tools/test/src/fake_devices.dart
+4
-1
No files found.
packages/flutter_tools/lib/src/base/user_messages.dart
View file @
a599c23b
...
@@ -247,8 +247,8 @@ class UserMessages {
...
@@ -247,8 +247,8 @@ class UserMessages {
String
get
flutterNoDevelopmentDevice
=>
String
get
flutterNoDevelopmentDevice
=>
"Unable to locate a development device; please run 'flutter doctor' "
"Unable to locate a development device; please run 'flutter doctor' "
'for information about installing additional components.'
;
'for information about installing additional components.'
;
String
flutterNoMatchingDevice
(
String
deviceId
)
=>
'No devices found with name or id '
String
flutterNoMatchingDevice
(
String
deviceId
)
=>
'No
supported
devices found with name or id '
"matching '
$deviceId
'"
;
"matching '
$deviceId
'
.
"
;
String
get
flutterNoDevicesFound
=>
'No devices found'
;
String
get
flutterNoDevicesFound
=>
'No devices found'
;
String
get
flutterNoSupportedDevices
=>
'No supported devices connected.'
;
String
get
flutterNoSupportedDevices
=>
'No supported devices connected.'
;
String
flutterMissPlatformProjects
(
List
<
String
>
unsupportedDevicesType
)
=>
String
flutterMissPlatformProjects
(
List
<
String
>
unsupportedDevicesType
)
=>
...
...
packages/flutter_tools/lib/src/device.dart
View file @
a599c23b
...
@@ -254,7 +254,8 @@ abstract class DeviceManager {
...
@@ -254,7 +254,8 @@ abstract class DeviceManager {
await
refreshAllConnectedDevices
(
timeout:
timeout
);
await
refreshAllConnectedDevices
(
timeout:
timeout
);
}
}
List
<
Device
>
devices
=
await
getDevices
();
List
<
Device
>
devices
=
(
await
getDevices
())
.
where
((
Device
device
)
=>
device
.
isSupported
()).
toList
();
// Always remove web and fuchsia devices from `--all`. This setting
// Always remove web and fuchsia devices from `--all`. This setting
// currently requires devices to share a frontend_server and resident
// currently requires devices to share a frontend_server and resident
...
...
packages/flutter_tools/lib/src/runner/flutter_command.dart
View file @
a599c23b
...
@@ -1364,6 +1364,12 @@ abstract class FlutterCommand extends Command<void> {
...
@@ -1364,6 +1364,12 @@ abstract class FlutterCommand extends Command<void> {
if
(
devices
.
isEmpty
&&
deviceManager
.
hasSpecifiedDeviceId
)
{
if
(
devices
.
isEmpty
&&
deviceManager
.
hasSpecifiedDeviceId
)
{
globals
.
printStatus
(
userMessages
.
flutterNoMatchingDevice
(
deviceManager
.
specifiedDeviceId
!));
globals
.
printStatus
(
userMessages
.
flutterNoMatchingDevice
(
deviceManager
.
specifiedDeviceId
!));
final
List
<
Device
>
allDevices
=
await
deviceManager
.
getAllConnectedDevices
();
if
(
allDevices
.
isNotEmpty
)
{
globals
.
printStatus
(
''
);
globals
.
printStatus
(
'The following devices were found:'
);
await
Device
.
printDevices
(
allDevices
,
globals
.
logger
);
}
return
null
;
return
null
;
}
else
if
(
devices
.
isEmpty
)
{
}
else
if
(
devices
.
isEmpty
)
{
if
(
deviceManager
.
hasSpecifiedAllDevices
)
{
if
(
deviceManager
.
hasSpecifiedAllDevices
)
{
...
...
packages/flutter_tools/test/commands.shard/hermetic/run_test.dart
View file @
a599c23b
...
@@ -195,6 +195,33 @@ void main() {
...
@@ -195,6 +195,33 @@ void main() {
Cache:
()
=>
Cache
.
test
(
processManager:
FakeProcessManager
.
any
()),
Cache:
()
=>
Cache
.
test
(
processManager:
FakeProcessManager
.
any
()),
});
});
testUsingContext
(
'exits and lists available devices when specified device not found'
,
()
async
{
final
RunCommand
command
=
RunCommand
();
final
FakeDevice
device
=
FakeDevice
(
isLocalEmulator:
true
);
mockDeviceManager
..
devices
=
<
Device
>[
device
]
..
hasSpecifiedDeviceId
=
true
;
await
expectLater
(
()
=>
createTestCommandRunner
(
command
).
run
(<
String
>[
'run'
,
'-d'
,
'invalid-device-id'
,
'--no-pub'
,
'--no-hot'
,
]),
throwsToolExit
(),
);
expect
(
testLogger
.
statusText
,
contains
(
"No supported devices found with name or id matching 'invalid-device-id'"
));
expect
(
testLogger
.
statusText
,
contains
(
'The following devices were found:'
));
expect
(
testLogger
.
statusText
,
contains
(
'FakeDevice (mobile) • fake_device • ios • (simulator)'
));
},
overrides:
<
Type
,
Generator
>{
DeviceManager:
()
=>
mockDeviceManager
,
FileSystem:
()
=>
fs
,
ProcessManager:
()
=>
FakeProcessManager
.
any
(),
Cache:
()
=>
Cache
.
test
(
processManager:
FakeProcessManager
.
any
()),
});
testUsingContext
(
'fails when targeted device is not Android with --device-user'
,
()
async
{
testUsingContext
(
'fails when targeted device is not Android with --device-user'
,
()
async
{
fs
.
file
(
'pubspec.yaml'
).
createSync
();
fs
.
file
(
'pubspec.yaml'
).
createSync
();
fs
.
file
(
'.packages'
).
writeAsStringSync
(
'
\n
'
);
fs
.
file
(
'.packages'
).
writeAsStringSync
(
'
\n
'
);
...
@@ -642,6 +669,9 @@ class FakeDeviceManager extends Fake implements DeviceManager {
...
@@ -642,6 +669,9 @@ class FakeDeviceManager extends Fake implements DeviceManager {
Future
<
List
<
Device
>>
findTargetDevices
(
FlutterProject
flutterProject
,
{
Duration
timeout
})
async
{
Future
<
List
<
Device
>>
findTargetDevices
(
FlutterProject
flutterProject
,
{
Duration
timeout
})
async
{
return
targetDevices
;
return
targetDevices
;
}
}
@override
Future
<
List
<
Device
>>
getAllConnectedDevices
()
async
=>
devices
;
}
}
class
FakeAndroidSdk
extends
Fake
implements
AndroidSdk
{
class
FakeAndroidSdk
extends
Fake
implements
AndroidSdk
{
...
...
packages/flutter_tools/test/general.shard/device_test.dart
View file @
a599c23b
...
@@ -179,6 +179,7 @@ void main() {
...
@@ -179,6 +179,7 @@ void main() {
final
FakeDevice
nonEphemeralOne
=
FakeDevice
(
'nonEphemeralOne'
,
'nonEphemeralOne'
,
ephemeral:
false
);
final
FakeDevice
nonEphemeralOne
=
FakeDevice
(
'nonEphemeralOne'
,
'nonEphemeralOne'
,
ephemeral:
false
);
final
FakeDevice
nonEphemeralTwo
=
FakeDevice
(
'nonEphemeralTwo'
,
'nonEphemeralTwo'
,
ephemeral:
false
);
final
FakeDevice
nonEphemeralTwo
=
FakeDevice
(
'nonEphemeralTwo'
,
'nonEphemeralTwo'
,
ephemeral:
false
);
final
FakeDevice
unsupported
=
FakeDevice
(
'unsupported'
,
'unsupported'
,
isSupported:
false
);
final
FakeDevice
unsupported
=
FakeDevice
(
'unsupported'
,
'unsupported'
,
isSupported:
false
);
final
FakeDevice
unsupportedForProject
=
FakeDevice
(
'unsupportedForProject'
,
'unsupportedForProject'
,
isSupportedForProject:
false
);
final
FakeDevice
webDevice
=
FakeDevice
(
'webby'
,
'webby'
)
final
FakeDevice
webDevice
=
FakeDevice
(
'webby'
,
'webby'
)
..
targetPlatform
=
Future
<
TargetPlatform
>.
value
(
TargetPlatform
.
web_javascript
);
..
targetPlatform
=
Future
<
TargetPlatform
>.
value
(
TargetPlatform
.
web_javascript
);
final
FakeDevice
fuchsiaDevice
=
FakeDevice
(
'fuchsiay'
,
'fuchsiay'
)
final
FakeDevice
fuchsiaDevice
=
FakeDevice
(
'fuchsiay'
,
'fuchsiay'
)
...
@@ -190,6 +191,7 @@ void main() {
...
@@ -190,6 +191,7 @@ void main() {
nonEphemeralOne
,
nonEphemeralOne
,
nonEphemeralTwo
,
nonEphemeralTwo
,
unsupported
,
unsupported
,
unsupportedForProject
,
];
];
final
DeviceManager
deviceManager
=
TestDeviceManager
(
final
DeviceManager
deviceManager
=
TestDeviceManager
(
...
@@ -327,9 +329,29 @@ void main() {
...
@@ -327,9 +329,29 @@ void main() {
);
);
});
});
testWithoutContext
(
'
Removes a single unsupported device
'
,
()
async
{
testWithoutContext
(
'
Unsupported devices listed in all connected devices
'
,
()
async
{
final
List
<
Device
>
devices
=
<
Device
>[
final
List
<
Device
>
devices
=
<
Device
>[
unsupported
,
unsupported
,
unsupportedForProject
,
];
final
DeviceManager
deviceManager
=
TestDeviceManager
(
devices
,
logger:
BufferLogger
.
test
(),
terminal:
Terminal
.
test
(),
);
final
List
<
Device
>
filtered
=
await
deviceManager
.
getAllConnectedDevices
();
expect
(
filtered
,
<
Device
>[
unsupported
,
unsupportedForProject
,
]);
});
testWithoutContext
(
'Removes a unsupported devices'
,
()
async
{
final
List
<
Device
>
devices
=
<
Device
>[
unsupported
,
unsupportedForProject
,
];
];
final
DeviceManager
deviceManager
=
TestDeviceManager
(
final
DeviceManager
deviceManager
=
TestDeviceManager
(
...
@@ -342,9 +364,10 @@ void main() {
...
@@ -342,9 +364,10 @@ void main() {
expect
(
filtered
,
<
Device
>[]);
expect
(
filtered
,
<
Device
>[]);
});
});
testWithoutContext
(
'
Does not remove an unsupported device
if FlutterProject is null'
,
()
async
{
testWithoutContext
(
'
Retains devices unsupported by the project
if FlutterProject is null'
,
()
async
{
final
List
<
Device
>
devices
=
<
Device
>[
final
List
<
Device
>
devices
=
<
Device
>[
unsupported
,
unsupported
,
unsupportedForProject
,
];
];
final
DeviceManager
deviceManager
=
TestDeviceManager
(
final
DeviceManager
deviceManager
=
TestDeviceManager
(
...
@@ -354,7 +377,7 @@ void main() {
...
@@ -354,7 +377,7 @@ void main() {
);
);
final
List
<
Device
>
filtered
=
await
deviceManager
.
findTargetDevices
(
null
);
final
List
<
Device
>
filtered
=
await
deviceManager
.
findTargetDevices
(
null
);
expect
(
filtered
,
<
Device
>[
unsupported
]);
expect
(
filtered
,
<
Device
>[
unsupported
ForProject
]);
});
});
testWithoutContext
(
'Removes web and fuchsia from --all'
,
()
async
{
testWithoutContext
(
'Removes web and fuchsia from --all'
,
()
async
{
...
@@ -374,11 +397,12 @@ void main() {
...
@@ -374,11 +397,12 @@ void main() {
expect
(
filtered
,
<
Device
>[]);
expect
(
filtered
,
<
Device
>[]);
});
});
testWithoutContext
(
'Removes
unsupported devices
from --all'
,
()
async
{
testWithoutContext
(
'Removes
devices unsupported by the project
from --all'
,
()
async
{
final
List
<
Device
>
devices
=
<
Device
>[
final
List
<
Device
>
devices
=
<
Device
>[
nonEphemeralOne
,
nonEphemeralOne
,
nonEphemeralTwo
,
nonEphemeralTwo
,
unsupported
,
unsupported
,
unsupportedForProject
,
];
];
final
DeviceManager
deviceManager
=
TestDeviceManager
(
final
DeviceManager
deviceManager
=
TestDeviceManager
(
devices
,
devices
,
...
@@ -398,18 +422,19 @@ void main() {
...
@@ -398,18 +422,19 @@ void main() {
testWithoutContext
(
'uses DeviceManager.isDeviceSupportedForProject instead of device.isSupportedForProject'
,
()
async
{
testWithoutContext
(
'uses DeviceManager.isDeviceSupportedForProject instead of device.isSupportedForProject'
,
()
async
{
final
List
<
Device
>
devices
=
<
Device
>[
final
List
<
Device
>
devices
=
<
Device
>[
unsupported
,
unsupported
,
unsupportedForProject
,
];
];
final
TestDeviceManager
deviceManager
=
TestDeviceManager
(
final
TestDeviceManager
deviceManager
=
TestDeviceManager
(
devices
,
devices
,
logger:
BufferLogger
.
test
(),
logger:
BufferLogger
.
test
(),
terminal:
Terminal
.
test
(),
terminal:
Terminal
.
test
(),
);
);
deviceManager
.
isAlwaysSupportedOverride
=
true
;
deviceManager
.
isAlwaysSupported
ForProject
Override
=
true
;
final
List
<
Device
>
filtered
=
await
deviceManager
.
findTargetDevices
(
FakeFlutterProject
());
final
List
<
Device
>
filtered
=
await
deviceManager
.
findTargetDevices
(
FakeFlutterProject
());
expect
(
filtered
,
<
Device
>[
expect
(
filtered
,
<
Device
>[
unsupported
,
unsupported
ForProject
,
]);
]);
});
});
...
@@ -513,12 +538,12 @@ class TestDeviceManager extends DeviceManager {
...
@@ -513,12 +538,12 @@ class TestDeviceManager extends DeviceManager {
_fakeDeviceDiscoverer
.
setDevices
(
allDevices
);
_fakeDeviceDiscoverer
.
setDevices
(
allDevices
);
}
}
bool
?
isAlwaysSupportedOverride
;
bool
?
isAlwaysSupported
ForProject
Override
;
@override
@override
bool
isDeviceSupportedForProject
(
Device
device
,
FlutterProject
?
flutterProject
)
{
bool
isDeviceSupportedForProject
(
Device
device
,
FlutterProject
?
flutterProject
)
{
if
(
isAlwaysSupportedOverride
!=
null
)
{
if
(
isAlwaysSupported
ForProject
Override
!=
null
)
{
return
isAlwaysSupportedOverride
!;
return
isAlwaysSupported
ForProject
Override
!;
}
}
return
super
.
isDeviceSupportedForProject
(
device
,
flutterProject
);
return
super
.
isDeviceSupportedForProject
(
device
,
flutterProject
);
}
}
...
...
packages/flutter_tools/test/integration.shard/flutter_run_test.dart
View file @
a599c23b
...
@@ -45,7 +45,7 @@ void main() {
...
@@ -45,7 +45,7 @@ void main() {
expect
(
proc
.
stdout
,
isNot
(
contains
(
'flutter has exited unexpectedly'
)));
expect
(
proc
.
stdout
,
isNot
(
contains
(
'flutter has exited unexpectedly'
)));
expect
(
proc
.
stderr
,
isNot
(
contains
(
'flutter has exited unexpectedly'
)));
expect
(
proc
.
stderr
,
isNot
(
contains
(
'flutter has exited unexpectedly'
)));
if
(!
proc
.
stderr
.
toString
().
contains
(
'Unable to locate a development'
)
if
(!
proc
.
stderr
.
toString
().
contains
(
'Unable to locate a development'
)
&&
!
proc
.
stdout
.
toString
().
contains
(
'No devices found with name or id matching'
))
{
&&
!
proc
.
stdout
.
toString
().
contains
(
'No
supported
devices found with name or id matching'
))
{
fail
(
"'flutter run -d invalid-device-id' did not produce the expected error"
);
fail
(
"'flutter run -d invalid-device-id' did not produce the expected error"
);
}
}
});
});
...
...
packages/flutter_tools/test/src/fake_devices.dart
View file @
a599c23b
...
@@ -61,9 +61,11 @@ class FakeDevice extends Device {
...
@@ -61,9 +61,11 @@ class FakeDevice extends Device {
FakeDevice
(
this
.
name
,
String
id
,
{
FakeDevice
(
this
.
name
,
String
id
,
{
bool
ephemeral
=
true
,
bool
ephemeral
=
true
,
bool
isSupported
=
true
,
bool
isSupported
=
true
,
bool
isSupportedForProject
=
true
,
PlatformType
type
=
PlatformType
.
web
,
PlatformType
type
=
PlatformType
.
web
,
LaunchResult
?
launchResult
,
LaunchResult
?
launchResult
,
})
:
_isSupported
=
isSupported
,
})
:
_isSupported
=
isSupported
,
_isSupportedForProject
=
isSupportedForProject
,
_launchResult
=
launchResult
??
LaunchResult
.
succeeded
(),
_launchResult
=
launchResult
??
LaunchResult
.
succeeded
(),
super
(
super
(
id
,
id
,
...
@@ -73,6 +75,7 @@ class FakeDevice extends Device {
...
@@ -73,6 +75,7 @@ class FakeDevice extends Device {
);
);
final
bool
_isSupported
;
final
bool
_isSupported
;
final
bool
_isSupportedForProject
;
final
LaunchResult
_launchResult
;
final
LaunchResult
_launchResult
;
@override
@override
...
@@ -110,7 +113,7 @@ class FakeDevice extends Device {
...
@@ -110,7 +113,7 @@ class FakeDevice extends Device {
void
noSuchMethod
(
Invocation
invocation
)
=>
super
.
noSuchMethod
(
invocation
);
void
noSuchMethod
(
Invocation
invocation
)
=>
super
.
noSuchMethod
(
invocation
);
@override
@override
bool
isSupportedForProject
(
FlutterProject
flutterProject
)
=>
_isSupported
;
bool
isSupportedForProject
(
FlutterProject
flutterProject
)
=>
_isSupported
ForProject
;
@override
@override
bool
isSupported
()
=>
_isSupported
;
bool
isSupported
()
=>
_isSupported
;
...
...
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