Unverified Commit 54326885 authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Migrate install command to null safety (#95433)

parent 8e9bca80
...@@ -543,6 +543,7 @@ class AndroidDevice extends Device { ...@@ -543,6 +543,7 @@ class AndroidDevice extends Device {
return LaunchResult.failed(); return LaunchResult.failed();
} }
AndroidApk? builtPackage = package;
AndroidArch androidArch; AndroidArch androidArch;
switch (devicePlatform) { switch (devicePlatform) {
case TargetPlatform.android_arm: case TargetPlatform.android_arm:
...@@ -587,18 +588,18 @@ class AndroidDevice extends Device { ...@@ -587,18 +588,18 @@ class AndroidDevice extends Device {
); );
// Package has been built, so we can get the updated application ID and // Package has been built, so we can get the updated application ID and
// activity name from the .apk. // activity name from the .apk.
package = await ApplicationPackageFactory.instance! builtPackage = await ApplicationPackageFactory.instance!
.getPackageForPlatform(devicePlatform, buildInfo: debuggingOptions.buildInfo) as AndroidApk; .getPackageForPlatform(devicePlatform, buildInfo: debuggingOptions.buildInfo) as AndroidApk?;
} }
// There was a failure parsing the android project information. // There was a failure parsing the android project information.
if (package == null) { if (builtPackage == null) {
throwToolExit('Problem building Android application: see above error(s).'); throwToolExit('Problem building Android application: see above error(s).');
} }
_logger.printTrace("Stopping app '${package.name}' on $name."); _logger.printTrace("Stopping app '${builtPackage.name}' on $name.");
await stopApp(package, userIdentifier: userIdentifier); await stopApp(builtPackage, userIdentifier: userIdentifier);
if (!await installApp(package, userIdentifier: userIdentifier)) { if (!await installApp(builtPackage, userIdentifier: userIdentifier)) {
return LaunchResult.failed(); return LaunchResult.failed();
} }
...@@ -672,7 +673,7 @@ class AndroidDevice extends Device { ...@@ -672,7 +673,7 @@ class AndroidDevice extends Device {
if (userIdentifier != null) if (userIdentifier != null)
...<String>['--user', userIdentifier], ...<String>['--user', userIdentifier],
], ],
package.launchActivity, builtPackage.launchActivity,
]; ];
final String result = (await runAdbCheckedAsync(cmd)).stdout; final String result = (await runAdbCheckedAsync(cmd)).stdout;
// This invocation returns 0 even when it fails. // This invocation returns 0 even when it fails.
...@@ -681,7 +682,7 @@ class AndroidDevice extends Device { ...@@ -681,7 +682,7 @@ class AndroidDevice extends Device {
return LaunchResult.failed(); return LaunchResult.failed();
} }
_package = package; _package = builtPackage;
if (!debuggingOptions.debuggingEnabled) { if (!debuggingOptions.debuggingEnabled) {
return LaunchResult.succeeded(); return LaunchResult.succeeded();
} }
......
...@@ -10,10 +10,10 @@ abstract class ApplicationPackageFactory { ...@@ -10,10 +10,10 @@ abstract class ApplicationPackageFactory {
static ApplicationPackageFactory? get instance => context.get<ApplicationPackageFactory>(); static ApplicationPackageFactory? get instance => context.get<ApplicationPackageFactory>();
/// Create an [ApplicationPackage] for the given platform. /// Create an [ApplicationPackage] for the given platform.
Future<ApplicationPackage> getPackageForPlatform( Future<ApplicationPackage?> getPackageForPlatform(
TargetPlatform platform, { TargetPlatform platform, {
BuildInfo buildInfo, BuildInfo? buildInfo,
File applicationBinary, File? applicationBinary,
}); });
} }
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import '../android/android_device.dart'; import '../android/android_device.dart';
import '../application_package.dart'; import '../application_package.dart';
import '../base/common.dart'; import '../base/common.dart';
...@@ -18,8 +16,6 @@ class InstallCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts ...@@ -18,8 +16,6 @@ class InstallCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts
usesDeviceUserOption(); usesDeviceUserOption();
usesDeviceTimeoutOption(); usesDeviceTimeoutOption();
argParser.addFlag('uninstall-only', argParser.addFlag('uninstall-only',
negatable: true,
defaultsTo: false,
help: 'Uninstall the app if already on the device. Skip install.', help: 'Uninstall the app if already on the device. Skip install.',
); );
} }
...@@ -33,10 +29,10 @@ class InstallCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts ...@@ -33,10 +29,10 @@ class InstallCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts
@override @override
final String category = FlutterCommandCategory.tools; final String category = FlutterCommandCategory.tools;
Device device; Device? device;
bool get uninstallOnly => boolArg('uninstall-only'); bool get uninstallOnly => boolArg('uninstall-only');
String get userIdentifier => stringArg(FlutterOptions.kDeviceUser); String? get userIdentifier => stringArg(FlutterOptions.kDeviceUser);
@override @override
Future<void> validateCommand() async { Future<void> validateCommand() async {
...@@ -52,19 +48,23 @@ class InstallCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts ...@@ -52,19 +48,23 @@ class InstallCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts
@override @override
Future<FlutterCommandResult> runCommand() async { Future<FlutterCommandResult> runCommand() async {
final ApplicationPackage package = await applicationPackages.getPackageForPlatform( final Device targetDevice = device!;
await device.targetPlatform, final ApplicationPackage? package = await applicationPackages?.getPackageForPlatform(
await targetDevice.targetPlatform,
); );
if (package == null) {
throwToolExit('Could not find or build package');
}
if (uninstallOnly) { if (uninstallOnly) {
await _uninstallApp(package); await _uninstallApp(package, targetDevice);
} else { } else {
await _installApp(package); await _installApp(package, targetDevice);
} }
return FlutterCommandResult.success(); return FlutterCommandResult.success();
} }
Future<void> _uninstallApp(ApplicationPackage package) async { Future<void> _uninstallApp(ApplicationPackage package, Device device) async {
if (await device.isAppInstalled(package, userIdentifier: userIdentifier)) { if (await device.isAppInstalled(package, userIdentifier: userIdentifier)) {
globals.printStatus('Uninstalling $package from $device...'); globals.printStatus('Uninstalling $package from $device...');
if (!await device.uninstallApp(package, userIdentifier: userIdentifier)) { if (!await device.uninstallApp(package, userIdentifier: userIdentifier)) {
...@@ -75,7 +75,7 @@ class InstallCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts ...@@ -75,7 +75,7 @@ class InstallCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts
} }
} }
Future<void> _installApp(ApplicationPackage package) async { Future<void> _installApp(ApplicationPackage package, Device device) async {
globals.printStatus('Installing $package to $device...'); globals.printStatus('Installing $package to $device...');
if (!await installApp(device, package, userIdentifier: userIdentifier)) { if (!await installApp(device, package, userIdentifier: userIdentifier)) {
...@@ -87,7 +87,7 @@ class InstallCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts ...@@ -87,7 +87,7 @@ class InstallCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts
Future<bool> installApp( Future<bool> installApp(
Device device, Device device,
ApplicationPackage package, { ApplicationPackage package, {
String userIdentifier, String? userIdentifier,
bool uninstall = true bool uninstall = true
}) async { }) async {
if (package == null) { if (package == null) {
......
...@@ -490,7 +490,7 @@ abstract class Device { ...@@ -490,7 +490,7 @@ abstract class Device {
/// Specify [userIdentifier] to check if installed for a particular user (Android only). /// Specify [userIdentifier] to check if installed for a particular user (Android only).
Future<bool> isAppInstalled( Future<bool> isAppInstalled(
covariant ApplicationPackage app, { covariant ApplicationPackage app, {
String userIdentifier, String? userIdentifier,
}); });
/// Check if the latest build of the [app] is already installed. /// Check if the latest build of the [app] is already installed.
......
...@@ -2,9 +2,6 @@ ...@@ -2,9 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:meta/meta.dart';
import 'package:process/process.dart'; import 'package:process/process.dart';
import 'android/android_sdk.dart'; import 'android/android_sdk.dart';
...@@ -28,11 +25,11 @@ import 'windows/application_package.dart'; ...@@ -28,11 +25,11 @@ import 'windows/application_package.dart';
/// A package factory that supports all Flutter target platforms. /// A package factory that supports all Flutter target platforms.
class FlutterApplicationPackageFactory extends ApplicationPackageFactory { class FlutterApplicationPackageFactory extends ApplicationPackageFactory {
FlutterApplicationPackageFactory({ FlutterApplicationPackageFactory({
@required AndroidSdk androidSdk, required AndroidSdk androidSdk,
@required ProcessManager processManager, required ProcessManager processManager,
@required Logger logger, required Logger logger,
@required UserMessages userMessages, required UserMessages userMessages,
@required FileSystem fileSystem, required FileSystem fileSystem,
}) : _androidSdk = androidSdk, }) : _androidSdk = androidSdk,
_processManager = processManager, _processManager = processManager,
_logger = logger, _logger = logger,
...@@ -49,10 +46,10 @@ class FlutterApplicationPackageFactory extends ApplicationPackageFactory { ...@@ -49,10 +46,10 @@ class FlutterApplicationPackageFactory extends ApplicationPackageFactory {
final FileSystem _fileSystem; final FileSystem _fileSystem;
@override @override
Future<ApplicationPackage> getPackageForPlatform( Future<ApplicationPackage?> getPackageForPlatform(
TargetPlatform platform, { TargetPlatform platform, {
BuildInfo buildInfo, BuildInfo? buildInfo,
File applicationBinary, File? applicationBinary,
}) async { }) async {
switch (platform) { switch (platform) {
case TargetPlatform.android: case TargetPlatform.android:
...@@ -111,7 +108,5 @@ class FlutterApplicationPackageFactory extends ApplicationPackageFactory { ...@@ -111,7 +108,5 @@ class FlutterApplicationPackageFactory extends ApplicationPackageFactory {
case TargetPlatform.windows_uwp_x64: case TargetPlatform.windows_uwp_x64:
return BuildableUwpApp(project: FlutterProject.current().windowsUwp); return BuildableUwpApp(project: FlutterProject.current().windowsUwp);
} }
assert(platform != null);
return null;
} }
} }
...@@ -72,7 +72,7 @@ abstract class IOSApp extends ApplicationPackage { ...@@ -72,7 +72,7 @@ abstract class IOSApp extends ApplicationPackage {
); );
} }
static Future<IOSApp?> fromIosProject(IosProject project, BuildInfo buildInfo) async { static Future<IOSApp?> fromIosProject(IosProject project, BuildInfo? buildInfo) async {
if (!globals.platform.isMacOS) { if (!globals.platform.isMacOS) {
return null; return null;
} }
...@@ -109,7 +109,7 @@ class BuildableIOSApp extends IOSApp { ...@@ -109,7 +109,7 @@ class BuildableIOSApp extends IOSApp {
: _hostAppBundleName = hostAppBundleName, : _hostAppBundleName = hostAppBundleName,
super(projectBundleId: projectBundleId); super(projectBundleId: projectBundleId);
static Future<BuildableIOSApp?> fromProject(IosProject project, BuildInfo buildInfo) async { static Future<BuildableIOSApp?> fromProject(IosProject project, BuildInfo? buildInfo) async {
final String? hostAppBundleName = await project.hostAppBundleName(buildInfo); final String? hostAppBundleName = await project.hostAppBundleName(buildInfo);
final String? projectBundleId = await project.productBundleIdentifier(buildInfo); final String? projectBundleId = await project.productBundleIdentifier(buildInfo);
if (projectBundleId != null) { if (projectBundleId != null) {
......
...@@ -216,7 +216,7 @@ class IosProject extends XcodeBasedProject { ...@@ -216,7 +216,7 @@ class IosProject extends XcodeBasedProject {
} }
/// The bundle name of the host app, `My App.app`. /// The bundle name of the host app, `My App.app`.
Future<String?> hostAppBundleName(BuildInfo buildInfo) async { Future<String?> hostAppBundleName(BuildInfo? buildInfo) async {
if (!existsSync()) { if (!existsSync()) {
return null; return null;
} }
...@@ -224,7 +224,7 @@ class IosProject extends XcodeBasedProject { ...@@ -224,7 +224,7 @@ class IosProject extends XcodeBasedProject {
} }
String? _hostAppBundleName; String? _hostAppBundleName;
Future<String> _parseHostAppBundleName(BuildInfo buildInfo) async { Future<String> _parseHostAppBundleName(BuildInfo? buildInfo) async {
// The product name and bundle name are derived from the display name, which the user // The product name and bundle name are derived from the display name, which the user
// is instructed to change in Xcode as part of deploying to the App Store. // is instructed to change in Xcode as part of deploying to the App Store.
// https://flutter.dev/docs/deployment/ios#review-xcode-project-settings // https://flutter.dev/docs/deployment/ios#review-xcode-project-settings
......
...@@ -489,7 +489,7 @@ class FakeIosProject extends Fake implements IosProject { ...@@ -489,7 +489,7 @@ class FakeIosProject extends Fake implements IosProject {
final File xcodeProjectInfoFile; final File xcodeProjectInfoFile;
@override @override
Future<String> hostAppBundleName(BuildInfo buildInfo) async => 'UnitTestRunner.app'; Future<String> hostAppBundleName(BuildInfo? buildInfo) async => 'UnitTestRunner.app';
@override @override
Directory get xcodeProject => xcodeProjectInfoFile.fileSystem.directory('Runner.xcodeproj'); Directory get xcodeProject => xcodeProjectInfoFile.fileSystem.directory('Runner.xcodeproj');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment