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