Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
Audit covariant usage in tool (#116930)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmagman authored Dec 15, 2022
1 parent f1d157b commit ada4460
Show file tree
Hide file tree
Showing 32 changed files with 120 additions and 118 deletions.
18 changes: 9 additions & 9 deletions packages/flutter_tools/lib/src/android/android_device.dart
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ class AndroidDevice extends Device {

@override
Future<bool> isAppInstalled(
AndroidApk app, {
ApplicationPackage app, {
String? userIdentifier,
}) async {
// This call takes 400ms - 600ms.
Expand All @@ -388,14 +388,14 @@ class AndroidDevice extends Device {
}

@override
Future<bool> isLatestBuildInstalled(AndroidApk app) async {
Future<bool> isLatestBuildInstalled(covariant AndroidApk app) async {
final String installedSha1 = await _getDeviceApkSha1(app);
return installedSha1.isNotEmpty && installedSha1 == _getSourceSha1(app);
}

@override
Future<bool> installApp(
AndroidApk app, {
covariant AndroidApk app, {
String? userIdentifier,
}) async {
if (!await _adbIsValid) {
Expand Down Expand Up @@ -478,7 +478,7 @@ class AndroidDevice extends Device {

@override
Future<bool> uninstallApp(
AndroidApk app, {
ApplicationPackage app, {
String? userIdentifier,
}) async {
if (!await _adbIsValid) {
Expand Down Expand Up @@ -519,7 +519,7 @@ class AndroidDevice extends Device {

@override
Future<LaunchResult> startApp(
AndroidApk package, {
AndroidApk? package, {
String? mainPath,
String? route,
required DebuggingOptions debuggingOptions,
Expand Down Expand Up @@ -721,11 +721,11 @@ class AndroidDevice extends Device {

@override
Future<bool> stopApp(
AndroidApk? app, {
ApplicationPackage? app, {
String? userIdentifier,
}) {
}) async {
if (app == null) {
return Future<bool>.value(false);
return false;
}
final List<String> command = adbCommandForDevice(<String>[
'shell',
Expand Down Expand Up @@ -767,7 +767,7 @@ class AndroidDevice extends Device {

@override
FutureOr<DeviceLogReader> getLogReader({
AndroidApk? app,
ApplicationPackage? app,
bool includePastLogs = false,
}) async {
// The Android log reader isn't app-specific. The `app` parameter isn't used.
Expand Down
19 changes: 11 additions & 8 deletions packages/flutter_tools/lib/src/custom_devices/custom_device.dart
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ class CustomDevice extends Device {
@override
final DevicePortForwarder portForwarder;

CustomDeviceAppSession _getOrCreateAppSession(covariant ApplicationPackage app) {
CustomDeviceAppSession _getOrCreateAppSession(ApplicationPackage app) {
return _sessions.putIfAbsent(
app,
() {
Expand Down Expand Up @@ -663,7 +663,7 @@ class CustomDevice extends Device {

@override
FutureOr<DeviceLogReader> getLogReader({
covariant ApplicationPackage? app,
ApplicationPackage? app,
bool includePastLogs = false
}) {
if (app != null) {
Expand All @@ -674,7 +674,7 @@ class CustomDevice extends Device {
}

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

@override
Future<bool> isAppInstalled(covariant ApplicationPackage app, {String? userIdentifier}) async {
Future<bool> isAppInstalled(ApplicationPackage app, {String? userIdentifier}) async {
return false;
}

@override
Future<bool> isLatestBuildInstalled(covariant ApplicationPackage app) async {
Future<bool> isLatestBuildInstalled(ApplicationPackage app) async {
return false;
}

Expand Down Expand Up @@ -742,7 +742,7 @@ class CustomDevice extends Device {

@override
Future<LaunchResult> startApp(
covariant ApplicationPackage package, {
ApplicationPackage package, {
String? mainPath,
String? route,
required DebuggingOptions debuggingOptions,
Expand Down Expand Up @@ -796,15 +796,18 @@ class CustomDevice extends Device {
}

@override
Future<bool> stopApp(covariant ApplicationPackage app, {String? userIdentifier}) {
Future<bool> stopApp(ApplicationPackage? app, {String? userIdentifier}) async {
if (app == null) {
return false;
}
return _getOrCreateAppSession(app).stop();
}

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

@override
Future<bool> uninstallApp(covariant ApplicationPackage app, {String? userIdentifier}) async {
Future<bool> uninstallApp(ApplicationPackage app, {String? userIdentifier}) async {
final String? appName = app.name;
if (appName == null) {
return false;
Expand Down
8 changes: 3 additions & 5 deletions packages/flutter_tools/lib/src/desktop_device.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ abstract class DesktopDevice extends Device {
final DesktopLogReader _deviceLogReader = DesktopLogReader();

@override
DevFSWriter createDevFSWriter(covariant ApplicationPackage? app, String? userIdentifier) {
DevFSWriter createDevFSWriter(ApplicationPackage? app, String? userIdentifier) {
return LocalDevFSWriter(fileSystem: _fileSystem);
}

Expand Down Expand Up @@ -117,7 +117,6 @@ abstract class DesktopDevice extends Device {
}) async {
if (!prebuiltApplication) {
await buildForDevice(
package,
buildInfo: debuggingOptions.buildInfo,
mainPath: mainPath,
);
Expand Down Expand Up @@ -179,7 +178,7 @@ abstract class DesktopDevice extends Device {

@override
Future<bool> stopApp(
ApplicationPackage app, {
ApplicationPackage? app, {
String? userIdentifier,
}) async {
bool succeeded = true;
Expand All @@ -197,8 +196,7 @@ abstract class DesktopDevice extends Device {
}

/// Builds the current project for this device, with the given options.
Future<void> buildForDevice(
ApplicationPackage package, {
Future<void> buildForDevice({
required BuildInfo buildInfo,
String? mainPath,
});
Expand Down
14 changes: 7 additions & 7 deletions packages/flutter_tools/lib/src/device.dart
Original file line number Diff line number Diff line change
Expand Up @@ -470,18 +470,18 @@ abstract class Device {
///
/// Specify [userIdentifier] to check if installed for a particular user (Android only).
Future<bool> isAppInstalled(
covariant ApplicationPackage app, {
ApplicationPackage app, {
String? userIdentifier,
});

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

/// Install an app package on the current device.
///
/// Specify [userIdentifier] to install for a particular user (Android only).
Future<bool> installApp(
covariant ApplicationPackage app, {
ApplicationPackage app, {
String? userIdentifier,
});

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

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

Expand Down Expand Up @@ -583,7 +583,7 @@ abstract class Device {
///
/// Specify [userIdentifier] to stop app installed to a profile (Android only).
Future<bool> stopApp(
covariant ApplicationPackage? app, {
ApplicationPackage? app, {
String? userIdentifier,
});

Expand Down
7 changes: 4 additions & 3 deletions packages/flutter_tools/lib/src/drive/drive_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,12 @@ class FlutterDriverService extends DriverService {
await sharedSkSlWriter(_device!, result, outputFile: writeSkslOnExit, logger: _logger);
}
// If the application package is available, stop and uninstall.
if (_applicationPackage != null) {
if (!await _device!.stopApp(_applicationPackage, userIdentifier: userIdentifier)) {
final ApplicationPackage? package = _applicationPackage;
if (package != null) {
if (!await _device!.stopApp(package, userIdentifier: userIdentifier)) {
_logger.printError('Failed to stop app');
}
if (!await _device!.uninstallApp(_applicationPackage!, userIdentifier: userIdentifier)) {
if (!await _device!.uninstallApp(package, userIdentifier: userIdentifier)) {
_logger.printError('Failed to uninstall app');
}
} else if (_device!.supportsFlutterExit) {
Expand Down
4 changes: 2 additions & 2 deletions packages/flutter_tools/lib/src/fuchsia/fuchsia_device.dart
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ class FuchsiaDevice extends Device {

@override
Future<LaunchResult> startApp(
covariant FuchsiaApp package, {
FuchsiaApp package, {
String? mainPath,
String? route,
required DebuggingOptions debuggingOptions,
Expand Down Expand Up @@ -471,7 +471,7 @@ class FuchsiaDevice extends Device {

@override
Future<bool> stopApp(
covariant FuchsiaApp app, {
ApplicationPackage? app, {
String? userIdentifier,
}) async {
if (await isSession) {
Expand Down
13 changes: 7 additions & 6 deletions packages/flutter_tools/lib/src/ios/devices.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:meta/meta.dart';
import 'package:process/process.dart';
import 'package:vm_service/vm_service.dart' as vm_service;

import '../application_package.dart';
import '../base/file_system.dart';
import '../base/io.dart';
import '../base/logger.dart';
Expand Down Expand Up @@ -225,7 +226,7 @@ class IOSDevice extends Device {

@override
Future<bool> isAppInstalled(
IOSApp app, {
ApplicationPackage app, {
String? userIdentifier,
}) async {
bool result;
Expand All @@ -242,11 +243,11 @@ class IOSDevice extends Device {
}

@override
Future<bool> isLatestBuildInstalled(IOSApp app) async => false;
Future<bool> isLatestBuildInstalled(ApplicationPackage app) async => false;

@override
Future<bool> installApp(
IOSApp app, {
covariant IOSApp app, {
String? userIdentifier,
}) async {
final Directory bundle = _fileSystem.directory(app.deviceBundlePath);
Expand Down Expand Up @@ -280,7 +281,7 @@ class IOSDevice extends Device {

@override
Future<bool> uninstallApp(
IOSApp app, {
ApplicationPackage app, {
String? userIdentifier,
}) async {
int uninstallationResult;
Expand Down Expand Up @@ -434,7 +435,7 @@ class IOSDevice extends Device {

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

@override
DeviceLogReader getLogReader({
IOSApp? app,
covariant IOSApp? app,
bool includePastLogs = false,
}) {
assert(!includePastLogs, 'Past log reading not supported on iOS devices.');
Expand Down
11 changes: 5 additions & 6 deletions packages/flutter_tools/lib/src/ios/simulators.dart
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ class IOSSimulator extends Device {
final SimControl _simControl;

@override
DevFSWriter createDevFSWriter(covariant ApplicationPackage? app, String? userIdentifier) {
DevFSWriter createDevFSWriter(ApplicationPackage? app, String? userIdentifier) {
return LocalDevFSWriter(fileSystem: globals.fs);
}

Expand Down Expand Up @@ -369,8 +369,7 @@ class IOSSimulator extends Device {
String? userIdentifier,
}) async {
try {
final IOSApp iosApp = app;
await _simControl.install(id, iosApp.simulatorBundlePath);
await _simControl.install(id, app.simulatorBundlePath);
return true;
} on Exception {
return false;
Expand Down Expand Up @@ -420,7 +419,7 @@ class IOSSimulator extends Device {

@override
Future<LaunchResult> startApp(
covariant IOSApp package, {
IOSApp package, {
String? mainPath,
String? route,
required DebuggingOptions debuggingOptions,
Expand Down Expand Up @@ -506,7 +505,7 @@ class IOSSimulator extends Device {
return LaunchResult.failed();
}

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

@override
DeviceLogReader getLogReader({
IOSApp? app,
covariant IOSApp? app,
bool includePastLogs = false,
}) {
assert(!includePastLogs, 'Past log reading not supported on iOS simulators.');
Expand Down
3 changes: 1 addition & 2 deletions packages/flutter_tools/lib/src/linux/linux_device.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ class LinuxDevice extends DesktopDevice {
}

@override
Future<void> buildForDevice(
covariant LinuxApp package, {
Future<void> buildForDevice({
String? mainPath,
required BuildInfo buildInfo,
}) async {
Expand Down
3 changes: 1 addition & 2 deletions packages/flutter_tools/lib/src/macos/macos_device.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ class MacOSDevice extends DesktopDevice {
}

@override
Future<void> buildForDevice(
covariant MacOSApp package, {
Future<void> buildForDevice({
required BuildInfo buildInfo,
String? mainPath,
}) async {
Expand Down
Loading

0 comments on commit ada4460

Please sign in to comment.