Handle null exception case in ProxiedDevice.stopApp. (#113317)
This commit is contained in:
@@ -1025,8 +1025,11 @@ class DeviceDomain extends Domain {
|
||||
if (device == null) {
|
||||
throw DaemonException("device '$deviceId' not found");
|
||||
}
|
||||
final String? applicationPackageId = _getStringArg(args, 'applicationPackageId', required: true);
|
||||
final ApplicationPackage applicationPackage = _applicationPackages[applicationPackageId!]!;
|
||||
final String? applicationPackageId = _getStringArg(args, 'applicationPackageId');
|
||||
ApplicationPackage? applicationPackage;
|
||||
if (applicationPackageId != null) {
|
||||
applicationPackage = _applicationPackages[applicationPackageId];
|
||||
}
|
||||
return device.stopApp(
|
||||
applicationPackage,
|
||||
userIdentifier: _getStringArg(args, 'userIdentifier'),
|
||||
|
||||
@@ -65,7 +65,7 @@ class ProxiedDevices extends DeviceDiscovery {
|
||||
final List<Map<String, Object?>> discoveredDevices = _cast<List<dynamic>>(await connection.sendRequest('device.discoverDevices')).cast<Map<String, Object?>>();
|
||||
final List<ProxiedDevice> devices = <ProxiedDevice>[
|
||||
for (final Map<String, Object?> device in discoveredDevices)
|
||||
_deviceFromDaemonResult(device),
|
||||
deviceFromDaemonResult(device),
|
||||
];
|
||||
|
||||
_devices = devices;
|
||||
@@ -75,7 +75,8 @@ class ProxiedDevices extends DeviceDiscovery {
|
||||
@override
|
||||
List<String> get wellKnownIds => const <String>[];
|
||||
|
||||
ProxiedDevice _deviceFromDaemonResult(Map<String, Object?> device) {
|
||||
@visibleForTesting
|
||||
ProxiedDevice deviceFromDaemonResult(Map<String, Object?> device) {
|
||||
final Map<String, Object?> capabilities = _cast<Map<String, Object?>>(device['capabilities']);
|
||||
return ProxiedDevice(
|
||||
connection, _cast<String>(device['id']),
|
||||
@@ -275,12 +276,13 @@ class ProxiedDevice extends Device {
|
||||
|
||||
@override
|
||||
Future<bool> stopApp(
|
||||
covariant PrebuiltApplicationPackage app, {
|
||||
covariant PrebuiltApplicationPackage? app, {
|
||||
String? userIdentifier,
|
||||
}) async {
|
||||
return _cast<bool>(await connection.sendRequest('device.stopApp', <String, Object?>{
|
||||
'deviceId': id,
|
||||
'applicationPackageId': await applicationPackageId(app),
|
||||
if (app != null)
|
||||
'applicationPackageId': await applicationPackageId(app),
|
||||
'userIdentifier': userIdentifier,
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -14,32 +14,32 @@ import 'package:test/fake.dart';
|
||||
import '../../src/common.dart';
|
||||
|
||||
void main() {
|
||||
late BufferLogger bufferLogger;
|
||||
late DaemonConnection serverDaemonConnection;
|
||||
late DaemonConnection clientDaemonConnection;
|
||||
setUp(() {
|
||||
bufferLogger = BufferLogger.test();
|
||||
final FakeDaemonStreams serverDaemonStreams = FakeDaemonStreams();
|
||||
serverDaemonConnection = DaemonConnection(
|
||||
daemonStreams: serverDaemonStreams,
|
||||
logger: bufferLogger,
|
||||
);
|
||||
final FakeDaemonStreams clientDaemonStreams = FakeDaemonStreams();
|
||||
clientDaemonConnection = DaemonConnection(
|
||||
daemonStreams: clientDaemonStreams,
|
||||
logger: bufferLogger,
|
||||
);
|
||||
|
||||
serverDaemonStreams.inputs.addStream(clientDaemonStreams.outputs.stream);
|
||||
clientDaemonStreams.inputs.addStream(serverDaemonStreams.outputs.stream);
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
await serverDaemonConnection.dispose();
|
||||
await clientDaemonConnection.dispose();
|
||||
});
|
||||
|
||||
group('ProxiedPortForwarder', () {
|
||||
late BufferLogger bufferLogger;
|
||||
late DaemonConnection serverDaemonConnection;
|
||||
late DaemonConnection clientDaemonConnection;
|
||||
setUp(() {
|
||||
bufferLogger = BufferLogger.test();
|
||||
final FakeDaemonStreams serverDaemonStreams = FakeDaemonStreams();
|
||||
serverDaemonConnection = DaemonConnection(
|
||||
daemonStreams: serverDaemonStreams,
|
||||
logger: bufferLogger,
|
||||
);
|
||||
final FakeDaemonStreams clientDaemonStreams = FakeDaemonStreams();
|
||||
clientDaemonConnection = DaemonConnection(
|
||||
daemonStreams: clientDaemonStreams,
|
||||
logger: bufferLogger,
|
||||
);
|
||||
|
||||
serverDaemonStreams.inputs.addStream(clientDaemonStreams.outputs.stream);
|
||||
clientDaemonStreams.inputs.addStream(serverDaemonStreams.outputs.stream);
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
await serverDaemonConnection.dispose();
|
||||
await clientDaemonConnection.dispose();
|
||||
});
|
||||
|
||||
testWithoutContext('works correctly without device id', () async {
|
||||
final FakeServerSocket fakeServerSocket = FakeServerSocket(200);
|
||||
final ProxiedPortForwarder portForwarder = ProxiedPortForwarder(
|
||||
@@ -202,6 +202,41 @@ void main() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
group('ProxiedDevice', () {
|
||||
final Map<String, Object> fakeDevice = <String, Object>{
|
||||
'name': 'device-name',
|
||||
'id': 'device-id',
|
||||
'category': 'mobile',
|
||||
'platformType': 'android',
|
||||
'platform': 'android-arm',
|
||||
'emulator': true,
|
||||
'ephemeral': false,
|
||||
'sdk': 'Test SDK (1.2.3)',
|
||||
'capabilities': <String, Object>{
|
||||
'hotReload': true,
|
||||
'hotRestart': true,
|
||||
'screenshot': false,
|
||||
'fastStart': false,
|
||||
'flutterExit': true,
|
||||
'hardwareRendering': true,
|
||||
'startPaused': true,
|
||||
},
|
||||
};
|
||||
testWithoutContext('calls stopApp without application package if not passed', () async {
|
||||
bufferLogger = BufferLogger.test();
|
||||
final ProxiedDevices proxiedDevices = ProxiedDevices(
|
||||
clientDaemonConnection,
|
||||
logger: bufferLogger,
|
||||
);
|
||||
final ProxiedDevice device = proxiedDevices.deviceFromDaemonResult(fakeDevice);
|
||||
unawaited(device.stopApp(null, userIdentifier: 'user-id'));
|
||||
final DaemonMessage message = await serverDaemonConnection.incomingCommands.first;
|
||||
expect(message.data['id'], isNotNull);
|
||||
expect(message.data['method'], 'device.stopApp');
|
||||
expect(message.data['params'], <String, Object?>{'deviceId': 'device-id', 'userIdentifier': 'user-id'});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
class FakeDaemonStreams implements DaemonStreams {
|
||||
|
||||
Reference in New Issue
Block a user