Skip to content

Commit ada4460

Browse files
authored
Audit covariant usage in tool (#116930)
1 parent f1d157b commit ada4460

32 files changed

+120
-118
lines changed

packages/flutter_tools/lib/src/android/android_device.dart

+9-9
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ class AndroidDevice extends Device {
366366

367367
@override
368368
Future<bool> isAppInstalled(
369-
AndroidApk app, {
369+
ApplicationPackage app, {
370370
String? userIdentifier,
371371
}) async {
372372
// This call takes 400ms - 600ms.
@@ -388,14 +388,14 @@ class AndroidDevice extends Device {
388388
}
389389

390390
@override
391-
Future<bool> isLatestBuildInstalled(AndroidApk app) async {
391+
Future<bool> isLatestBuildInstalled(covariant AndroidApk app) async {
392392
final String installedSha1 = await _getDeviceApkSha1(app);
393393
return installedSha1.isNotEmpty && installedSha1 == _getSourceSha1(app);
394394
}
395395

396396
@override
397397
Future<bool> installApp(
398-
AndroidApk app, {
398+
covariant AndroidApk app, {
399399
String? userIdentifier,
400400
}) async {
401401
if (!await _adbIsValid) {
@@ -478,7 +478,7 @@ class AndroidDevice extends Device {
478478

479479
@override
480480
Future<bool> uninstallApp(
481-
AndroidApk app, {
481+
ApplicationPackage app, {
482482
String? userIdentifier,
483483
}) async {
484484
if (!await _adbIsValid) {
@@ -519,7 +519,7 @@ class AndroidDevice extends Device {
519519

520520
@override
521521
Future<LaunchResult> startApp(
522-
AndroidApk package, {
522+
AndroidApk? package, {
523523
String? mainPath,
524524
String? route,
525525
required DebuggingOptions debuggingOptions,
@@ -721,11 +721,11 @@ class AndroidDevice extends Device {
721721

722722
@override
723723
Future<bool> stopApp(
724-
AndroidApk? app, {
724+
ApplicationPackage? app, {
725725
String? userIdentifier,
726-
}) {
726+
}) async {
727727
if (app == null) {
728-
return Future<bool>.value(false);
728+
return false;
729729
}
730730
final List<String> command = adbCommandForDevice(<String>[
731731
'shell',
@@ -767,7 +767,7 @@ class AndroidDevice extends Device {
767767

768768
@override
769769
FutureOr<DeviceLogReader> getLogReader({
770-
AndroidApk? app,
770+
ApplicationPackage? app,
771771
bool includePastLogs = false,
772772
}) async {
773773
// The Android log reader isn't app-specific. The `app` parameter isn't used.

packages/flutter_tools/lib/src/custom_devices/custom_device.dart

+11-8
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ class CustomDevice extends Device {
475475
@override
476476
final DevicePortForwarder portForwarder;
477477

478-
CustomDeviceAppSession _getOrCreateAppSession(covariant ApplicationPackage app) {
478+
CustomDeviceAppSession _getOrCreateAppSession(ApplicationPackage app) {
479479
return _sessions.putIfAbsent(
480480
app,
481481
() {
@@ -663,7 +663,7 @@ class CustomDevice extends Device {
663663

664664
@override
665665
FutureOr<DeviceLogReader> getLogReader({
666-
covariant ApplicationPackage? app,
666+
ApplicationPackage? app,
667667
bool includePastLogs = false
668668
}) {
669669
if (app != null) {
@@ -674,7 +674,7 @@ class CustomDevice extends Device {
674674
}
675675

676676
@override
677-
Future<bool> installApp(covariant ApplicationPackage app, {String? userIdentifier}) async {
677+
Future<bool> installApp(ApplicationPackage app, {String? userIdentifier}) async {
678678
final String? appName = app.name;
679679
if (appName == null || !await tryUninstall(appName: appName)) {
680680
return false;
@@ -689,12 +689,12 @@ class CustomDevice extends Device {
689689
}
690690

691691
@override
692-
Future<bool> isAppInstalled(covariant ApplicationPackage app, {String? userIdentifier}) async {
692+
Future<bool> isAppInstalled(ApplicationPackage app, {String? userIdentifier}) async {
693693
return false;
694694
}
695695

696696
@override
697-
Future<bool> isLatestBuildInstalled(covariant ApplicationPackage app) async {
697+
Future<bool> isLatestBuildInstalled(ApplicationPackage app) async {
698698
return false;
699699
}
700700

@@ -742,7 +742,7 @@ class CustomDevice extends Device {
742742

743743
@override
744744
Future<LaunchResult> startApp(
745-
covariant ApplicationPackage package, {
745+
ApplicationPackage package, {
746746
String? mainPath,
747747
String? route,
748748
required DebuggingOptions debuggingOptions,
@@ -796,15 +796,18 @@ class CustomDevice extends Device {
796796
}
797797

798798
@override
799-
Future<bool> stopApp(covariant ApplicationPackage app, {String? userIdentifier}) {
799+
Future<bool> stopApp(ApplicationPackage? app, {String? userIdentifier}) async {
800+
if (app == null) {
801+
return false;
802+
}
800803
return _getOrCreateAppSession(app).stop();
801804
}
802805

803806
@override
804807
Future<TargetPlatform> get targetPlatform async => _config.platform ?? TargetPlatform.linux_arm64;
805808

806809
@override
807-
Future<bool> uninstallApp(covariant ApplicationPackage app, {String? userIdentifier}) async {
810+
Future<bool> uninstallApp(ApplicationPackage app, {String? userIdentifier}) async {
808811
final String? appName = app.name;
809812
if (appName == null) {
810813
return false;

packages/flutter_tools/lib/src/desktop_device.dart

+3-5
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ abstract class DesktopDevice extends Device {
4444
final DesktopLogReader _deviceLogReader = DesktopLogReader();
4545

4646
@override
47-
DevFSWriter createDevFSWriter(covariant ApplicationPackage? app, String? userIdentifier) {
47+
DevFSWriter createDevFSWriter(ApplicationPackage? app, String? userIdentifier) {
4848
return LocalDevFSWriter(fileSystem: _fileSystem);
4949
}
5050

@@ -117,7 +117,6 @@ abstract class DesktopDevice extends Device {
117117
}) async {
118118
if (!prebuiltApplication) {
119119
await buildForDevice(
120-
package,
121120
buildInfo: debuggingOptions.buildInfo,
122121
mainPath: mainPath,
123122
);
@@ -179,7 +178,7 @@ abstract class DesktopDevice extends Device {
179178

180179
@override
181180
Future<bool> stopApp(
182-
ApplicationPackage app, {
181+
ApplicationPackage? app, {
183182
String? userIdentifier,
184183
}) async {
185184
bool succeeded = true;
@@ -197,8 +196,7 @@ abstract class DesktopDevice extends Device {
197196
}
198197

199198
/// Builds the current project for this device, with the given options.
200-
Future<void> buildForDevice(
201-
ApplicationPackage package, {
199+
Future<void> buildForDevice({
202200
required BuildInfo buildInfo,
203201
String? mainPath,
204202
});

packages/flutter_tools/lib/src/device.dart

+7-7
Original file line numberDiff line numberDiff line change
@@ -470,18 +470,18 @@ abstract class Device {
470470
///
471471
/// Specify [userIdentifier] to check if installed for a particular user (Android only).
472472
Future<bool> isAppInstalled(
473-
covariant ApplicationPackage app, {
473+
ApplicationPackage app, {
474474
String? userIdentifier,
475475
});
476476

477477
/// Check if the latest build of the [app] is already installed.
478-
Future<bool> isLatestBuildInstalled(covariant ApplicationPackage app);
478+
Future<bool> isLatestBuildInstalled(ApplicationPackage app);
479479

480480
/// Install an app package on the current device.
481481
///
482482
/// Specify [userIdentifier] to install for a particular user (Android only).
483483
Future<bool> installApp(
484-
covariant ApplicationPackage app, {
484+
ApplicationPackage app, {
485485
String? userIdentifier,
486486
});
487487

@@ -490,7 +490,7 @@ abstract class Device {
490490
/// Specify [userIdentifier] to uninstall for a particular user,
491491
/// defaults to all users (Android only).
492492
Future<bool> uninstallApp(
493-
covariant ApplicationPackage app, {
493+
ApplicationPackage app, {
494494
String? userIdentifier,
495495
});
496496

@@ -516,7 +516,7 @@ abstract class Device {
516516
/// For example, the desktop device classes can use a writer which
517517
/// copies the files across the local file system.
518518
DevFSWriter? createDevFSWriter(
519-
covariant ApplicationPackage? app,
519+
ApplicationPackage? app,
520520
String? userIdentifier,
521521
) {
522522
return null;
@@ -531,7 +531,7 @@ abstract class Device {
531531
/// reader will also include log messages from before the invocation time.
532532
/// Defaults to false.
533533
FutureOr<DeviceLogReader> getLogReader({
534-
covariant ApplicationPackage? app,
534+
ApplicationPackage? app,
535535
bool includePastLogs = false,
536536
});
537537

@@ -583,7 +583,7 @@ abstract class Device {
583583
///
584584
/// Specify [userIdentifier] to stop app installed to a profile (Android only).
585585
Future<bool> stopApp(
586-
covariant ApplicationPackage? app, {
586+
ApplicationPackage? app, {
587587
String? userIdentifier,
588588
});
589589

packages/flutter_tools/lib/src/drive/drive_service.dart

+4-3
Original file line numberDiff line numberDiff line change
@@ -296,11 +296,12 @@ class FlutterDriverService extends DriverService {
296296
await sharedSkSlWriter(_device!, result, outputFile: writeSkslOnExit, logger: _logger);
297297
}
298298
// If the application package is available, stop and uninstall.
299-
if (_applicationPackage != null) {
300-
if (!await _device!.stopApp(_applicationPackage, userIdentifier: userIdentifier)) {
299+
final ApplicationPackage? package = _applicationPackage;
300+
if (package != null) {
301+
if (!await _device!.stopApp(package, userIdentifier: userIdentifier)) {
301302
_logger.printError('Failed to stop app');
302303
}
303-
if (!await _device!.uninstallApp(_applicationPackage!, userIdentifier: userIdentifier)) {
304+
if (!await _device!.uninstallApp(package, userIdentifier: userIdentifier)) {
304305
_logger.printError('Failed to uninstall app');
305306
}
306307
} else if (_device!.supportsFlutterExit) {

packages/flutter_tools/lib/src/fuchsia/fuchsia_device.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ class FuchsiaDevice extends Device {
293293

294294
@override
295295
Future<LaunchResult> startApp(
296-
covariant FuchsiaApp package, {
296+
FuchsiaApp package, {
297297
String? mainPath,
298298
String? route,
299299
required DebuggingOptions debuggingOptions,
@@ -471,7 +471,7 @@ class FuchsiaDevice extends Device {
471471

472472
@override
473473
Future<bool> stopApp(
474-
covariant FuchsiaApp app, {
474+
ApplicationPackage? app, {
475475
String? userIdentifier,
476476
}) async {
477477
if (await isSession) {

packages/flutter_tools/lib/src/ios/devices.dart

+7-6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'package:meta/meta.dart';
88
import 'package:process/process.dart';
99
import 'package:vm_service/vm_service.dart' as vm_service;
1010

11+
import '../application_package.dart';
1112
import '../base/file_system.dart';
1213
import '../base/io.dart';
1314
import '../base/logger.dart';
@@ -225,7 +226,7 @@ class IOSDevice extends Device {
225226

226227
@override
227228
Future<bool> isAppInstalled(
228-
IOSApp app, {
229+
ApplicationPackage app, {
229230
String? userIdentifier,
230231
}) async {
231232
bool result;
@@ -242,11 +243,11 @@ class IOSDevice extends Device {
242243
}
243244

244245
@override
245-
Future<bool> isLatestBuildInstalled(IOSApp app) async => false;
246+
Future<bool> isLatestBuildInstalled(ApplicationPackage app) async => false;
246247

247248
@override
248249
Future<bool> installApp(
249-
IOSApp app, {
250+
covariant IOSApp app, {
250251
String? userIdentifier,
251252
}) async {
252253
final Directory bundle = _fileSystem.directory(app.deviceBundlePath);
@@ -280,7 +281,7 @@ class IOSDevice extends Device {
280281

281282
@override
282283
Future<bool> uninstallApp(
283-
IOSApp app, {
284+
ApplicationPackage app, {
284285
String? userIdentifier,
285286
}) async {
286287
int uninstallationResult;
@@ -434,7 +435,7 @@ class IOSDevice extends Device {
434435

435436
@override
436437
Future<bool> stopApp(
437-
IOSApp app, {
438+
ApplicationPackage? app, {
438439
String? userIdentifier,
439440
}) async {
440441
// If the debugger is not attached, killing the ios-deploy process won't stop the app.
@@ -453,7 +454,7 @@ class IOSDevice extends Device {
453454

454455
@override
455456
DeviceLogReader getLogReader({
456-
IOSApp? app,
457+
covariant IOSApp? app,
457458
bool includePastLogs = false,
458459
}) {
459460
assert(!includePastLogs, 'Past log reading not supported on iOS devices.');

packages/flutter_tools/lib/src/ios/simulators.dart

+5-6
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ class IOSSimulator extends Device {
327327
final SimControl _simControl;
328328

329329
@override
330-
DevFSWriter createDevFSWriter(covariant ApplicationPackage? app, String? userIdentifier) {
330+
DevFSWriter createDevFSWriter(ApplicationPackage? app, String? userIdentifier) {
331331
return LocalDevFSWriter(fileSystem: globals.fs);
332332
}
333333

@@ -369,8 +369,7 @@ class IOSSimulator extends Device {
369369
String? userIdentifier,
370370
}) async {
371371
try {
372-
final IOSApp iosApp = app;
373-
await _simControl.install(id, iosApp.simulatorBundlePath);
372+
await _simControl.install(id, app.simulatorBundlePath);
374373
return true;
375374
} on Exception {
376375
return false;
@@ -420,7 +419,7 @@ class IOSSimulator extends Device {
420419

421420
@override
422421
Future<LaunchResult> startApp(
423-
covariant IOSApp package, {
422+
IOSApp package, {
424423
String? mainPath,
425424
String? route,
426425
required DebuggingOptions debuggingOptions,
@@ -506,7 +505,7 @@ class IOSSimulator extends Device {
506505
return LaunchResult.failed();
507506
}
508507

509-
Future<void> _setupUpdatedApplicationBundle(covariant BuildableIOSApp app, BuildInfo buildInfo, String? mainPath) async {
508+
Future<void> _setupUpdatedApplicationBundle(BuildableIOSApp app, BuildInfo buildInfo, String? mainPath) async {
510509
// Step 1: Build the Xcode project.
511510
// The build mode for the simulator is always debug.
512511
assert(buildInfo.isDebug);
@@ -574,7 +573,7 @@ class IOSSimulator extends Device {
574573

575574
@override
576575
DeviceLogReader getLogReader({
577-
IOSApp? app,
576+
covariant IOSApp? app,
578577
bool includePastLogs = false,
579578
}) {
580579
assert(!includePastLogs, 'Past log reading not supported on iOS simulators.');

packages/flutter_tools/lib/src/linux/linux_device.dart

+1-2
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ class LinuxDevice extends DesktopDevice {
5757
}
5858

5959
@override
60-
Future<void> buildForDevice(
61-
covariant LinuxApp package, {
60+
Future<void> buildForDevice({
6261
String? mainPath,
6362
required BuildInfo buildInfo,
6463
}) async {

packages/flutter_tools/lib/src/macos/macos_device.dart

+1-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ class MacOSDevice extends DesktopDevice {
6565
}
6666

6767
@override
68-
Future<void> buildForDevice(
69-
covariant MacOSApp package, {
68+
Future<void> buildForDevice({
7069
required BuildInfo buildInfo,
7170
String? mainPath,
7271
}) async {

0 commit comments

Comments
 (0)